Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Component Lifetimes #1

Open
dbuksbaum opened this issue Aug 25, 2011 · 2 comments
Open

Support Component Lifetimes #1

dbuksbaum opened this issue Aug 25, 2011 · 2 comments
Assignees
Labels

Comments

@dbuksbaum
Copy link
Owner

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.

@ghost ghost assigned dbuksbaum Aug 25, 2011
@tracstarr
Copy link

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("key")

to get my scopes.

@dbuksbaum
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants