1

Closed

RegisterInstance depends on UsesDefaultLifetimeManagerOf?

description

You say: "Warning: If you used the RegisterInstance method, then the same instance will be returned regardless of which lifetime manager is used."
 
But I have this:
 
protected void Application_Start()
{
// RequestLifetime is our default!!!
ILifetimeManager requestLifetimeManager = new Munq.LifetimeManagers.RequestLifetime();
serviceLocator.UsesDefaultLifetimeManagerOf(requestLifetimeManager);
 
// RegisterInstance?
serviceLocator.RegisterInstance<ILogger>(new NLogLogger());
 
// This is OK
serviceLocator.Resolve<ILogger>().Info("Application is starting...");
}
 
protected void Application_End()
{
// But I get error here - null
serviceLocator.Resolve<ILogger>().Info("Application is shutting down...");
}
 
But when coding this way:
 
// RegisterInstance - ContainerLifetime
serviceLocator.RegisterInstance<ILogger>(new NLogLogger())
    .WithLifetimeManager(new Munq.LifetimeManagers.ContainerLifetime());
 
I can log on Application_End
Closed Jun 3, 2010 at 9:51 PM by mdennis
Corrected

comments

mdennis wrote Jun 1, 2010 at 2:02 AM

Was caching and retrieving the instance using the DefaultLifetimeManager instead of the Container.
fixed in latest source http://munq.codeplex.com/SourceControl/changeset/changes/46927