Exemple #1
0
        /// <summary>
        /// Creates a scoped service provider
        /// </summary>
        /// <returns></returns>
        public IServiceScope CreateScope()
        {
            var scope = _locatorScopeFactory.CreateScope();

            return(new ServiceScope
                   (
                       new ServiceProvider
                       (
                           scope.Get <IServiceProviderTypeChecker>(),
                           scope.Get <ILocatorScopedAccessor>()
                       )
                   ));
        }
        /// <summary>
        /// Opens and closes a scoped locator
        /// </summary>
        /// <param name="applicationContext"></param>
        public virtual void OpenLocatorScope(HttpApplication applicationContext)
        {
            applicationContext.BeginRequest += (sender, args) =>
            {
                var x             = sender as HttpApplication;
                var context       = x.Context;
                var scopedLocator = _LocatorScopeFactory.CreateScope();
                context.Items.Add(ScopedLocatorKeyInContext, scopedLocator);
            };

            applicationContext.EndRequest += (sender, args) =>
            {
                var x       = sender as HttpApplication;
                var context = x.Context;
                var scope   = context.Items[ScopedLocatorKeyInContext] as ILocator;
                scope?.Dispose();
            };
        }
 /// <summary>
 /// Open a scoped locator
 /// </summary>
 /// <returns></returns>
 public IDependencyScope BeginScope()
 {
     return(new WebApiDependencyResolver(_LocatorScopeFactory.CreateScope(), _PipelineScope, _ServiceProviderTypeChecker, _HttpContextProvider));
 }
 /// <summary>
 /// Open a scoped locator
 /// </summary>
 /// <returns></returns>
 public IDependencyScope BeginScope()
 {
     return(new NullableWebApiDependencyResolver(_LocatorScopeFactory.CreateScope(), _LocatorScopeFactory, _HttpContextProvider, _ReflectionHelper, _PipelineScope, _AllowableNullForGetService, _AllowableNullForGetServices));
 }