public IDependencyConfigurator Add( Type serviceType, Type implementationType, InstanceLifetime lifetime) { this.services.Add(ServiceDescriptor.Describe(serviceType, implementationType, ParseLifetime(lifetime))); return(this); }
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); }
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)); }
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; }
public MessagePipeOptions() { this.DefaultAsyncPublishStrategy = AsyncPublishStrategy.Parallel; this.InstanceLifetime = InstanceLifetime.Singleton; this.EnableCaptureStackTrace = false; this.HandlingSubscribeDisposedPolicy = HandlingSubscribeDisposedPolicy.Ignore; this.autoregistrationAssemblies = null; this.autoregistrationTypes = null; }
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)); }
public ResourceMeta(Type resourceType, Type implementationType, InstanceLifetime lifetime) { Guard.ArgumentNotNull(resourceType, "resourceType"); Guard.ArgumentNotNull(implementationType, "implementationType"); _resourceType = resourceType; _implementationType = implementationType; _lifetime = lifetime; }
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(); } }
public void Add(Type type, InstanceLifetime lifetime) { if (lifetime == InstanceLifetime.Scoped) { builder.Bind(type).AsCached(); } else { builder.Bind(type).AsSingle(); } }
public IDependencyConfigurator Add <TService>(InstanceLifetime lifetime) where TService : class { this.services.Add( ServiceDescriptor.Describe( typeof(TService), typeof(TService), ParseLifetime(lifetime))); return(this); }
private void SetScope(ScopeConcreteIdArgConditionCopyNonLazyBinder binder, InstanceLifetime lifetime) { if (lifetime == InstanceLifetime.Transient) { binder.AsTransient(); } else { binder.AsCached(); } }
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); }
/// <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); }
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 }
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; }
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()); }
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); } }
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); }
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; }
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); } }
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>()); }
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); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { BeforeDisposeOverride(); InstanceLifetime.Dispose(); }
static void Add(this IServiceCollection services, Type serviceType, InstanceLifetime scope) { services.Add(serviceType, serviceType, scope); }
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); }
//using real blobstorage public override void RegisterBlobStorage(InstanceLifetime lifeTime, string blobContainerName, string storageAccountSettingsvalue) { Di.Register <IBlobStorageDb, BlobStorageDb>(lifeTime, blobContainerName.ToString(), new object[] { storageAccountSettingsvalue, blobContainerName }); }
public override void RegisterQueue(InstanceLifetime lifeTime, string queueName, string storageAccountSettingsvalue) { Di.RegisterInstance <IQueue>(new AzureQueueMock(), queueName.ToString()); }
public override void RegisterTableStorageDb <TType>(InstanceLifetime lifeTime, string tableName, string storageAccountSettingsvalue) { Di.Register <ITableStorageDb <TType>, TableStorageDbMock <TType> >(InstanceLifetime.ReturnSameInstanceForEachResolve); }
/// <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); }
/// <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)); }