Пример #1
0
        protected void Application_End()
        {
            GlobalHandle <ILifetimeScope> .GetCurrentRef()
            .Resolve <ILog>().Warning("The application is about to close!");

            GlobalHandle <ILifetimeScope> .Current.Dispose();
        }
 public AdminController(ILog logger, AuthDao auth = null)
     : base(logger)
 {
     if (auth == null)
     {
         _authDao = GlobalHandle <ILifetimeScope> .GetCurrentRef().Resolve <AuthDao>();
     }
     else
     {
         _authDao = auth;
     }
 }
Пример #3
0
        /// <summary>
        /// 需要对Mvc5的升级支持
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static ILifetimeScope GetContainer(ContainerBuilder builder)
        {
            IContainer container = builder.Build();

            ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container));
            var autofacDependencyResolver = new AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(autofacDependencyResolver);
            GlobalHandle <ILifetimeScope> .Initialize(autofacDependencyResolver.ApplicationContainer);

            return(GlobalHandle <ILifetimeScope> .GetCurrentRef());
        }
Пример #4
0
        /// <summary>
        /// 全局句柄初始化
        /// </summary>
        /// <param name="resolver">解析器</param>
        public static ILifetimeScope GlobalInitialize(this AutofacDependencyResolver resolver)
        {
            GlobalHandle <ILifetimeScope> .Initialize(resolver.RequestLifetimeScope);

            return(GlobalHandle <ILifetimeScope> .GetCurrentRef());
        }