예제 #1
0
        /// <summary>
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IIocAppConfiguration UseAutofac(this IAppConfiguration configuration)
        {
            Ensure.NotNull(configuration, nameof(configuration));
            var registrar = new IocRegistrar(new ContainerBuilder());

            registrar.RegisterInstance(registrar);
            registrar.RegisterInstance <IIocRegistrar>(registrar);
            //registrar.RegisterInstance<IIocResolver>(registrar);//不能注册成实例(单例模式)
            registrar.Register <ILifetimeScopeProvider, LifetimeScopeProvider>();
            registrar.Register <IIocResolver, IocResolver>();
            registrar.Register <IIocScopeResolverFactory, AutofacServiceScopeFactory>();

            registrar.Register <DynamicProxyInterceptor>();

            return(configuration.CreateIocAppConfiguration(registrar,
                                                           new IocResolver(new LifetimeScopeProvider(registrar, null))));
        }
예제 #2
0
 public LifetimeScopeProvider(IocRegistrar registrar, ILifetimeScope scope)
 {
     _registrar = registrar;
     _scope     = scope;
 }