Example #1
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());
        }
Example #2
0
        /// <summary>
        /// 全局句柄初始化
        /// </summary>
        /// <param name="resolver">解析器</param>
        public static ILifetimeScope GlobalInitialize(this AutofacDependencyResolver resolver)
        {
            GlobalHandle <ILifetimeScope> .Initialize(resolver.RequestLifetimeScope);

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