Caliburn.Micro.Autofac
Caliburn.Micro.Autofac copied to clipboard
Support Component Lifetimes
From blog comment: http://buksbaum.us/2010/08/20/bootstrapping-caliburn-micro-with-autofac/comment-page-1/#comment-1694
tracstarr August 24th, 2011 at 21:41 Reply | Quote | Edit | #3 What about when I need to use specific lifetimescope within a using from a viewmodel? How can I do this without exposing the container? Or will I just have to?
using (var scope = Container.BeginLifetimeScope(“Commit”)) { …. }
david August 24th, 2011 at 22:53 Reply | Quote | Edit | #4 Good question. I don’t have an answer yet, but I will give it some thought. Can you provide a use case for this?
tracstarr August 25th, 2011 at 07:25 Reply | Quote | Edit | #5 Well, in my case it’s for accessing my data layer services. I use the lifetimescope in this way to make sure I don’t have a constant open connection and instances of service classes open.
What I’ve done since this post was to expose the container property as public, and then in the GetInstance i added:
if (serviceType == this.GetType()) return this
That allows me to use IoC.Get().Container.BeginLifetimeScope
It’s the only thing i’ve come up with so far.
So i've since changed this. the first thing in the TYpedBootStrapper.GetInstance is now:
if (serviceType == typeof(ILifetimeScope)) { if (string.IsNullOrEmpty(key)) return Container.BeginLifetimeScope(); return Container.BeginLifetimeScope(key);
}
This then allows me to simply use:
IoC.Get<ILifetimeScope>("key")
to get my scopes.
see http://stackoverflow.com/questions/10400849/how-to-dispose-of-autofac-container-used-with-caliburn-micro for related information