コード例 #1
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public void Register(Type @interface, Type service, LifeScope lifeScope = LifeScope.Transient)
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType(service).As(@interface).SetLifeScope(lifeScope);
            builder.Update(container);
        }
コード例 #2
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public void Register <TInterface, TService>(string name, LifeScope lifeScope = LifeScope.Transient) where TService : TInterface
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <TService>().As <TInterface>().Named(name, typeof(TInterface)).SetLifeScope(lifeScope);
            builder.Update(container);
        }
コード例 #3
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public void Register <TService>(LifeScope lifeScope = LifeScope.Transient)
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <TService>().AsSelf().SetLifeScope(lifeScope);
            builder.Update(container);
        }
コード例 #4
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public void Register(Type service, string name, LifeScope lifeScope = LifeScope.Transient)
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType(service).Named(name, service).SetLifeScope(lifeScope);
            builder.Update(container);
        }
コード例 #5
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public void Register(Type @interface, Type type, string name, LifeScope lifeScope = LifeScope.Transient)
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType(type).As(@interface).Named(name, @interface).SetLifeScope(lifeScope);
            builder.Update(container);
        }
コード例 #6
0
        public void Register <TService>(TService instance, Type aliasType, LifeScope lifeScope = LifeScope.Single) where TService : class
        {
            var registerBuilder = _builder.RegisterInstance(instance).SetLifeScope(lifeScope);

            if (aliasType != null)
            {
                registerBuilder.As(aliasType);
            }
        }
コード例 #7
0
ファイル: Container.cs プロジェクト: tkratena/essence-ioc
        public IDisposable Resolve <TService>(out TService service) where TService : class
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(nameof(Container));
            }

            var transientLifeScope = new LifeScope();

            service = _resolver.Resolve <TService>(transientLifeScope);
            return(transientLifeScope);
        }
コード例 #8
0
        public void RegisterType <TService>(string serviceName = null, LifeScope life = LifeScope.Singleton)
        {
            var registrationBuilder = _containerBuilder.RegisterType <TService>();

            if (serviceName != null)
            {
                registrationBuilder.Named <TService>(serviceName);
            }
            switch (life)
            {
            case LifeScope.PerDependency:
                registrationBuilder.InstancePerDependency();
                break;

            case LifeScope.Singleton:
                registrationBuilder.SingleInstance();
                break;
            }
        }
コード例 #9
0
 public static void Register <TService>(LifeScope lifeScope = LifeScope.Single)
 {
     _container.Register <TService>(lifeScope);
 }
コード例 #10
0
 public static void Register(Type serviceType, LifeScope lifeScope = LifeScope.Single)
 {
     _container.Register(serviceType, lifeScope);
 }
コード例 #11
0
        public Configuration SetDefault <TInterface, TService>(LifeScope lifeScope = LifeScope.Transient) where TService : TInterface
        {
            Container.Current.Register <TInterface, TService>(lifeScope);

            return(this);
        }
コード例 #12
0
 /// <summary>
 /// 注册一个Service类型的实现类
 /// </summary>
 /// <typeparam name="TSerivce"></typeparam>
 /// <typeparam name="TImplementer"></typeparam>
 /// <param name="serviceName"></param>
 /// <param name="life"></param>
 public static void Register <TSerivce, TImplementer>(string serviceName = null, LifeScope life = LifeScope.Singleton)
     where TSerivce : class
     where TImplementer : class, TSerivce
 {
     Current.Register <TSerivce, TImplementer>(serviceName, life);
 }
コード例 #13
0
 internal static IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> SetLifeScope <TLimit, TActivatorData, TRegistrationStyle>(this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registerInfo, LifeScope lifeScope)
 {
     if (lifeScope == LifeScope.Single)
     {
         registerInfo.SingleInstance();
     }
     return(registerInfo);
 }
コード例 #14
0
ファイル: AutofacContainer.cs プロジェクト: FRindWan/Husky
        public static IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> SetLifeScope <TLimit, TReflectionActivatorData, TStyle>(this IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> builder, LifeScope lifeScope)
        {
            if (lifeScope == LifeScope.Single)
            {
                return(builder.SingleInstance());
            }

            return(builder);
        }
コード例 #15
0
 /// <summary>
 /// 注册类型
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <param name="serviceName"></param>
 /// <param name="life"></param>
 public static void RegisterType <TService>(string serviceName = null, LifeScope life = LifeScope.Singleton)
 {
     Current.RegisterType <TService>(serviceName, life);
 }
コード例 #16
0
        public void RegisterType(Type serviceType, Type implementationType, string serviceName = null, LifeScope life = LifeScope.Singleton)
        {
            var registrationBuilder = _containerBuilder.RegisterType(implementationType).As(serviceType);

            if (serviceName != null)
            {
                registrationBuilder.Named(serviceName, serviceType);
            }
            switch (life)
            {
            case LifeScope.PerDependency:
                registrationBuilder.InstancePerDependency();
                break;

            case LifeScope.Singleton:
                registrationBuilder.SingleInstance();
                break;
            }
        }
コード例 #17
0
 public static void RegisterInstance <TService>(TService instance, Type aliasType = null, LifeScope lifeScope = LifeScope.Single) where TService : class
 {
     _container.Register(instance, aliasType, lifeScope);
 }
コード例 #18
0
 public Configuration SetDefault <TService, TImplementer>(string serviceName = null, LifeScope life = LifeScope.Singleton)
     where TService : class
     where TImplementer : class, TService
 {
     ObjectContainer.Register <TService, TImplementer>(serviceName, life);
     return(this);
 }
コード例 #19
0
 public void Register <TService>(LifeScope lifeScope = LifeScope.Single)
 {
     _builder.RegisterType <TService>().SetLifeScope(lifeScope);
 }
コード例 #20
0
 public void Register(Type serviceType, LifeScope lifeScope = LifeScope.Single)
 {
     _builder.RegisterType(serviceType).SetLifeScope(lifeScope);
 }
コード例 #21
0
 /// <summary>
 /// 注册一个Service类型的实现类
 /// </summary>
 /// <param name="serviceType"></param>
 /// <param name="implementationType"></param>
 /// <param name="serviceName"></param>
 /// <param name="life"></param>
 public static void RegisterType(Type serviceType, Type implementationType, string serviceName = null, LifeScope life = LifeScope.Singleton)
 {
     Current.RegisterType(serviceType, implementationType, serviceName, life);
 }