RegisterInstance depends on UsesDefaultLifetimeManagerOf?


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();
// 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 10:51 PM by mdennis


mdennis wrote Jun 1, 2010 at 3: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

wrote Jun 3, 2010 at 10:51 PM

wrote Feb 14, 2013 at 4:01 AM

wrote May 16, 2013 at 9:57 AM