コード例 #1
0
 public IDependencyConfigurator Add(
     Type serviceType,
     Type implementationType,
     InstanceLifetime lifetime)
 {
     this.services.Add(ServiceDescriptor.Describe(serviceType, implementationType, ParseLifetime(lifetime)));
     return(this);
 }
コード例 #2
0
 public IDependencyConfigurator Add <TImplementation>(
     Type serviceType,
     Func <IDependencyResolver, TImplementation> factory,
     InstanceLifetime lifetime)
 {
     this.services.Add(ServiceDescriptor.Describe(serviceType, provider => factory(new MicrosoftDependencyResolver(provider)), ParseLifetime(lifetime)));
     return(this);
 }
コード例 #3
0
        internal static void Add(this IServiceCollection services, Type serviceType, InstanceLifetime lifetime)
        {
            var lt = (lifetime == InstanceLifetime.Scoped) ? ServiceLifetime.Scoped
                   : (lifetime == InstanceLifetime.Singleton) ? ServiceLifetime.Singleton
                   : ServiceLifetime.Transient;

            services.Add(new ServiceDescriptor(serviceType, serviceType, lt));
        }
コード例 #4
0
        public ServiceMeta(Type implementationType, string serviceName, InitializationMode initializationMode, InstanceLifetime lifetime)
        {
            Guard.ArgumentNotNull(implementationType, "implementationType");

            _implementationType = implementationType;
            _serviceName        = (!string.IsNullOrEmpty(serviceName)) ? serviceName : _implementationType.FullName;
            _initializationMode = initializationMode;
            _lifetime           = lifetime;
        }
コード例 #5
0
 public MessagePipeOptions()
 {
     this.DefaultAsyncPublishStrategy     = AsyncPublishStrategy.Parallel;
     this.InstanceLifetime                = InstanceLifetime.Singleton;
     this.EnableCaptureStackTrace         = false;
     this.HandlingSubscribeDisposedPolicy = HandlingSubscribeDisposedPolicy.Ignore;
     this.autoregistrationAssemblies      = null;
     this.autoregistrationTypes           = null;
 }
コード例 #6
0
 public void Register <TInterface, TImplementation>(InstanceLifetime lifeTime, string name, params object[] constructorArguments) where TImplementation : TInterface
 {
     UnityContainer.RegisterType(
         typeof(TInterface),
         typeof(TImplementation),
         name,
         lifeTime.AsLifetimeManager(),
         GetConstructorInjection(constructorArguments));
 }
コード例 #7
0
        public ResourceMeta(Type resourceType, Type implementationType, InstanceLifetime lifetime)
        {
            Guard.ArgumentNotNull(resourceType, "resourceType");
            Guard.ArgumentNotNull(implementationType, "implementationType");

            _resourceType       = resourceType;
            _implementationType = implementationType;
            _lifetime           = lifetime;
        }
コード例 #8
0
 public void Add(Type serviceType, Type implementationType, InstanceLifetime lifetime)
 {
     if (lifetime == InstanceLifetime.Scoped)
     {
         builder.Bind(serviceType).To(implementationType).AsCached();
     }
     else
     {
         builder.Bind(serviceType).To(implementationType).AsSingle();
     }
 }
コード例 #9
0
 public void Add(Type type, InstanceLifetime lifetime)
 {
     if (lifetime == InstanceLifetime.Scoped)
     {
         builder.Bind(type).AsCached();
     }
     else
     {
         builder.Bind(type).AsSingle();
     }
 }
コード例 #10
0
        public IDependencyConfigurator Add <TService>(InstanceLifetime lifetime)
            where TService : class
        {
            this.services.Add(
                ServiceDescriptor.Describe(
                    typeof(TService),
                    typeof(TService),
                    ParseLifetime(lifetime)));

            return(this);
        }
コード例 #11
0
 private void SetScope(ScopeConcreteIdArgConditionCopyNonLazyBinder binder, InstanceLifetime lifetime)
 {
     if (lifetime == InstanceLifetime.Transient)
     {
         binder.AsTransient();
     }
     else
     {
         binder.AsCached();
     }
 }
コード例 #12
0
        public IDependencyConfigurator Add <TService, TImplementation>(InstanceLifetime lifetime)
            where TService : class
            where TImplementation : class, TService
        {
            this.services.Add(
                ServiceDescriptor.Describe(
                    typeof(TService),
                    typeof(TImplementation),
                    ParseLifetime(lifetime)));

            return(this);
        }
コード例 #13
0
ファイル: SimpleIoc.cs プロジェクト: itfenom/BackBock
        /// <summary>
        /// Registers a given instance for a given type and a given key.
        /// </summary>
        /// <typeparam name="TClass">The type that is being registered.</typeparam>
        /// <param name="factory">The factory method able to create the instance that
        /// must be returned when the given type is resolved.</param>
        /// <param name="key">The key for which the given instance is registered.</param>
        public ILifetimeConfig <TClass> RegisterWithLifetime <TClass>(InstanceLifetime lifetime, Func <TClass> factory, string key) where TClass : class
        {
            lock (this.@lock)
            {
                var classType = typeof(TClass);

                if (this.interfaceToClassMap.ContainsKey(classType))
                {
                    this.interfaceToClassMap[classType] = null;
                }
                else
                {
                    this.interfaceToClassMap.Add(classType, null);
                    var ii = new InstanceInfo(classType, classType, lifetime);
                    this.instanceInfos.Add(classType, ii);
                }

                if (this.instancesRegistry.ContainsKey(classType) &&
                    this.instancesRegistry[classType].ContainsKey(key))
                {
                    this.instancesRegistry[classType].Remove(key);
                }

                if (this.factories.ContainsKey(classType))
                {
                    if (this.factories[classType].ContainsKey(key))
                    {
                        this.factories[classType][key] = factory;
                    }
                    else
                    {
                        this.factories[classType].Add(key, factory);
                    }
                }
                else
                {
                    var list = new Dictionary <string, Delegate>
                    {
                        {
                            key,
                            factory
                        }
                    };

                    this.factories.Add(classType, list);
                }
            }

            var ilm = new LifetimeManager <TClass>(lifetime);

            lifetime.LifetimeManager = ilm;
            return(ilm);
        }
コード例 #14
0
        public MessagePipeOptions()
        {
            this.DefaultAsyncPublishStrategy     = AsyncPublishStrategy.Parallel;
            this.InstanceLifetime                = InstanceLifetime.Singleton;
            this.RequestHandlerLifetime          = InstanceLifetime.Scoped;
            this.EnableCaptureStackTrace         = false;
            this.HandlingSubscribeDisposedPolicy = HandlingSubscribeDisposedPolicy.Ignore;
#if !UNITY_2018_3_OR_NEWER
            this.EnableAutoRegistration     = true;
            this.autoregistrationAssemblies = null;
            this.autoregistrationTypes      = null;
#endif
        }
コード例 #15
0
        public ConstructionPlan(IRegistration registration, Dictionary <Type, HashSet <ConstructionPlan> > otherPlans, IConstructorSelectionStrategy selector, MultipleMappingsBehaviour multipleMappingsBehaviour = MultipleMappingsBehaviour.FailConstruction)
        {
            Guard.Against.Null(registration, nameof(registration));
            Guard.Against.Null(otherPlans, nameof(otherPlans));
            Guard.Against.Null(selector, nameof(selector));

            Declared = registration.DefinedType;
            Injected = registration.InjectedType;
            this.multipleMappingsBehaviour = multipleMappingsBehaviour;
            plans = otherPlans;
            constructorSelector = selector;
            lifetime            = registration.Lifetime;
        }
コード例 #16
0
        internal static LifetimeManager AsLifetimeManager(this InstanceLifetime instanceLifeTime)
        {
            switch (instanceLifeTime)
            {
            case InstanceLifetime.ReturnNewInstanceForEachResolve:
                return(new TransientLifetimeManager());

            case InstanceLifetime.ReturnNewInstanceForEachThread:
                return(new PerThreadLifetimeManager());

            case InstanceLifetime.ReturnSameInstanceForEachResolve:
                return(new ContainerControlledLifetimeManager());
            }

            return(new TransientLifetimeManager());
        }
コード例 #17
0
        private static ServiceLifetime ParseLifetime(InstanceLifetime lifetime)
        {
            switch (lifetime)
            {
            case InstanceLifetime.Singleton:
                return(ServiceLifetime.Singleton);

            case InstanceLifetime.Scoped:
                return(ServiceLifetime.Scoped);

            case InstanceLifetime.Transient:
                return(ServiceLifetime.Transient);

            default:
                throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null);
            }
        }
コード例 #18
0
ファイル: SimpleIoc.cs プロジェクト: itfenom/BackBock
        public ILifetimeConfig <TClass> Register <TInterface, TClass>(InstanceLifetime lifetime) where TClass : class, TInterface
        {
            // Todo: Implement
            //throw new NotImplementedException();

            lock (this.@lock)
            {
                var interfaceType = typeof(TInterface);
                var classType     = typeof(TClass);

                this.Register(interfaceType, classType, lifetime);
            }

            var ilm = new LifetimeManager <TClass>(lifetime);

            lifetime.LifetimeManager = ilm;
            return(ilm);
        }
コード例 #19
0
        public ChannelObserverMeta(Type channelType, Type observerType, string channelKey, string observerName, ThreadOption threadOption,
                                   InitializationMode initializationMode, InstanceLifetime lifetime)
        {
            Guard.ArgumentNotNull(channelType, "channelType");
            Guard.ArgumentNotNull(observerType, "observerType");
            if (string.IsNullOrEmpty(observerName))
            {
                observerName = observerType.FullName;
            }

            _channelType        = channelType;
            _observerType       = observerType;
            _channelKey         = channelKey;
            _observerName       = observerName;
            _lifetime           = lifetime;
            _threadOption       = threadOption;
            _initializationMode = initializationMode;
        }
コード例 #20
0
ファイル: SimpleIoc.cs プロジェクト: itfenom/BackBock
        public ILifetimeConfig <TClass> RegisterWithLifetime <TClass>(InstanceLifetime lifetime) where TClass : class
        {
            lock (this.@lock)
            {
                var classType = typeof(TClass);

                // IInstanceLifetime resultLifetime;
#if WIN8
                if (classType.GetTypeInfo().IsInterface)
#else
                if (classType.IsInterface)
#endif
                {
                    throw new ArgumentException("An interface cannot be registered alone");
                }

                if (this.interfaceToClassMap.ContainsKey(classType))
                {
                    this.interfaceToClassMap[classType] = null;
                    lifetime = new DummyInstanceHelper();
                }
                else
                {
                    this.interfaceToClassMap.Add(classType, null);
                    var ii = new InstanceInfo(classType, classType, lifetime);
                    this.instanceInfos.Add(classType, ii);
                }

                if (this.factories.ContainsKey(classType))
                {
                    this.factories.Remove(classType);
                }

                var ilm = new LifetimeManager <TClass>(lifetime);
                lifetime.LifetimeManager = ilm;
                return(ilm);
            }
        }
コード例 #21
0
        public ICommandsBuilder Use <TItem>(InstanceLifetime instanceLifetime)
            where TItem : IUseCommandsBuilder
        {
            switch (instanceLifetime)
            {
            case InstanceLifetime.Dependency:
                _containerBuilder.RegisterType <TItem>().InstancePerDependency();
                break;

            case InstanceLifetime.Pipeline:
                _containerBuilder.RegisterType <TItem>().InstancePerLifetimeScope();
                break;

            case InstanceLifetime.Singleton:
                _containerBuilder.RegisterType <TItem>().SingleInstance();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(instanceLifetime), instanceLifetime, null);
            }

            return(base.Use <TItem>());
        }
コード例 #22
0
        private void CheckAndRegisterType(Func <Type> getter, Type @interface, InstanceLifetime lifetime = InstanceLifetime.ReturnNewInstanceForEachResolve, bool tolerateNull = false)
        {
            var classType = getter();

            if (classType == null)
            {
                if (tolerateNull)
                {
                    return;
                }
                else
                {
                    throw new ArgumentException($"Gitt type var null");
                }
            }

            if (!Implements(classType, @interface))
            {
                throw new ArgumentException($"Gitt type implementerer ikke {@interface.Name}");
            }

            Register(@interface, classType, lifetime);
        }
コード例 #23
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     BeforeDisposeOverride();
     InstanceLifetime.Dispose();
 }
コード例 #24
0
 static void Add(this IServiceCollection services, Type serviceType, InstanceLifetime scope)
 {
     services.Add(serviceType, serviceType, scope);
 }
コード例 #25
0
        static void Add(this IServiceCollection services, Type serviceType, Type implementationType, InstanceLifetime scope)
        {
            var lifetime = (scope == InstanceLifetime.Scoped) ? ServiceLifetime.Scoped
                : (scope == InstanceLifetime.Singleton) ? ServiceLifetime.Singleton
                : ServiceLifetime.Transient;

            var descriptor = new ServiceDescriptor(serviceType, implementationType, lifetime);

            services.Add(descriptor);
        }
コード例 #26
0
 //using real blobstorage
 public override void RegisterBlobStorage(InstanceLifetime lifeTime, string blobContainerName, string storageAccountSettingsvalue)
 {
     Di.Register <IBlobStorageDb, BlobStorageDb>(lifeTime, blobContainerName.ToString(), new object[] { storageAccountSettingsvalue, blobContainerName });
 }
コード例 #27
0
 public override void RegisterQueue(InstanceLifetime lifeTime, string queueName, string storageAccountSettingsvalue)
 {
     Di.RegisterInstance <IQueue>(new AzureQueueMock(), queueName.ToString());
 }
コード例 #28
0
 public override void RegisterTableStorageDb <TType>(InstanceLifetime lifeTime, string tableName, string storageAccountSettingsvalue)
 {
     Di.Register <ITableStorageDb <TType>, TableStorageDbMock <TType> >(InstanceLifetime.ReturnSameInstanceForEachResolve);
 }
コード例 #29
0
 /// <summary>
 /// Set the handler lifetime. The default value is <see cref="InstanceLifetime.Singleton"/>
 /// </summary>
 /// <param name="lifetime"></param>
 /// <returns></returns>
 public TypedHandlerConfigurationBuilder WithHandlerLifetime(InstanceLifetime lifetime)
 {
     this.serviceLifetime = lifetime;
     return(this);
 }
コード例 #30
0
ファイル: SimpleIoc.cs プロジェクト: itfenom/BackBock
 /// <summary>
 /// Registers a given instance for a given type.
 /// </summary>
 /// <typeparam name="TClass">The type that is being registered.</typeparam>
 /// <param name="factory">The factory method able to create the instance that
 /// must be returned when the given type is resolved.</param>
 public ILifetimeConfig <TClass> RegisterWithLifetime <TClass>(InstanceLifetime lifetime, Func <TClass> factory) where TClass : class
 {
     return(RegisterWithLifetime(lifetime, factory, this.uniqueKey));
 }