Created
April 15, 2015 09:21
-
-
Save alexeyzimarev/0209c8dce783bbf347c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AutofacIocAdapter : IContainerAdapter | |
{ | |
private readonly IContainer _container; | |
public AutofacIocAdapter(IContainer container) | |
{ | |
_container = container; | |
} | |
private ILifetimeScope CurrentScope | |
{ | |
get | |
{ | |
return HttpContext.Current.Items["AutofacScope"] as ILifetimeScope; | |
} | |
} | |
public T Resolve<T>() | |
{ | |
return CurrentScope == null ? _container.Resolve<T>() : CurrentScope.Resolve<T>(); | |
} | |
public T TryResolve<T>() | |
{ | |
T result; | |
return CurrentScope == null | |
? _container.TryResolve(out result) ? result : default(T) | |
: CurrentScope.TryResolve(out result) ? result : default(T); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment