public AutofacOwinDependencyResolver(ILifetimeScope container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            _container = container;
            _rootDependencyScope = new AutofacOwinDependencyScope(container);
        }
 public override async Task Invoke(IOwinContext context)
 {
     if (context.Request.Path == "/random")
     {
         IOwinDependencyScope dependencyScope = context.GetRequestDependencyScope();
         IRepository          repository      = dependencyScope.GetService(typeof(IRepository)) as IRepository;
         await context.Response.WriteAsync(repository.GetRandomText());
     }
     else
     {
         await Next.Invoke(context);
     }
 }
 public OwinDependencyScopeWebApiAdapter(IOwinDependencyScope owinDependencyScope)
 {
     _owinDependencyScope = owinDependencyScope;
 }
Пример #4
0
        public static IDependencyScope GetOwinDependencyScope(this HttpRequestMessage request)
        {
            IOwinDependencyScope owinDependencyScope = request.GetOwinContext().GetRequestDependencyScope();

            return(new OwinDependencyScopeWebApiAdapter(owinDependencyScope));
        }
Пример #5
0
        public IDependencyScope BeginScope()
        {
            IOwinDependencyScope owinScope = _owinResolver.BeginScope();

            return(new OwinDependencyScopeWebApiAdapter(owinScope));
        }