internal ServiceDescriptor(Type serviceType, ServiceLifecycle lifecycle, object instance, Func <IServicesContainer, object> factory)
 {
     Lifecycle        = lifecycle;
     ServiceType      = serviceType;
     _serviceInstance = instance;
     _factory         = factory;
 }
		protected override void DoRegisterType(Type from, Type to, string name, ServiceLifecycle lifecycle)
		{
			if (to == null)
			{
				to = from;
			}

			if (String.IsNullOrEmpty(name))
			{
				name = to.FullName;
			}

			// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
			if (lifecycle == ServiceLifecycle.Singleton)
			{
				_container.Register(Component.For(from).ImplementedBy(to).Named(name).LifestyleSingleton());
			}
			else
			{
				_container.Register(Component.For(from).ImplementedBy(to).Named(name).LifestyleTransient());
			}
			// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
		}
 public void Register <TService>(Func <IServicesContainer, TService> factory, ServiceLifecycle lifecyle = ServiceLifecycle.Scoped) where TService : class
 {
     Register(new ServiceDescriptor(typeof(TService), lifecyle, null, factory));
 }
		public RegisterTypeAttribute(Type type, ServiceLifecycle lifecycle)
		{
			Verify.ArgumentNotNull(type, "type", out _type);
			_lifecycle = lifecycle;
		}
		public IServiceContainer RegisterType(Type from, Type to, string name, ServiceLifecycle lifecycle)
		{
			ThrowIfDisposed();
			DoRegisterType(from, to, name, lifecycle);
			return this;
		}
		protected abstract void DoRegisterType(Type from, Type to, string name, ServiceLifecycle lifecycle);
Exemple #7
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Register a service in the store context
 /// </summary>
 /// <typeparam name="T">
 ///  Type of the service
 /// </typeparam>
 /// <param name="service">
 ///  The factory used to instanciate the service
 /// </param>
 /// <param name="lifecycle">
 ///  The service life cycle
 /// </param>
 /// <returns>
 ///  A StoreBuilder.
 /// </returns>
 ///-------------------------------------------------------------------------------------------------
 public StoreBuilder Using <T>(Func <IServicesContainer, T> service, ServiceLifecycle lifecycle = ServiceLifecycle.Scoped) where T : class
 {
     _services.Register <T>(service, lifecycle);
     return(this);
 }