Exemplo n.º 1
0
        /// <summary>
        /// Registers the specified service factory.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <param name="serviceFactory">The service factory.</param>
        /// <param name="scope">Scope for service</param>

        public virtual void Register <TService>(Func <TService> serviceFactory, ScopeServiceEnum scope = ScopeServiceEnum.Transient) where TService : class
        {
            if (this._logger.InfoIsEnabled)
            {
                this._logger.Info("Register Type {0} in mode {1}", typeof(TService), scope);
            }

            this.InternalRegister <TService>(serviceFactory, scope);
        }
        /// <summary>
        /// Registers the specified scope.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <param name="scope">The scope.</param>
        public override void Register <TService, TImplementation>(ScopeServiceEnum scope = ScopeServiceEnum.TRANSIENT)
        {
            if (this.Logger.InfoIsEnabled)
            {
                this.Logger.Info("Register Type {0} with instance {1}  in {2} scope mode", typeof(TService), typeof(TImplementation), scope);
            }

            switch (scope)
            {
            case ScopeServiceEnum.TRANSIENT:
                this._container.Register <TService, TImplementation>(Lifestyle.Transient);
                break;

            case ScopeServiceEnum.SINGLETON:
                this._container.Register <TService, TImplementation>(Lifestyle.Singleton);
                break;

            default:
                throw new NotSupportedException();
            }
        }
        /// <summary>
        /// Internals the register.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <param name="serviceFactory">The service factory.</param>
        /// <param name="scope">The scope.</param>
        protected override void InternalRegister <TService>(Func <TService> serviceFactory, ScopeServiceEnum scope)
        {
            switch (scope)
            {
            case ScopeServiceEnum.TRANSIENT:
                this._container.Register <TService>(serviceFactory, Lifestyle.Transient);
                break;

            case ScopeServiceEnum.SINGLETON:
                this._container.Register <TService>(serviceFactory, Lifestyle.Singleton);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Registers this instance.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <typeparam name="TImplementation">Type of instance of service</typeparam>
 /// <param name="scope">Scope for service</param>
 public virtual void Register <TService, TImplementation>(ScopeServiceEnum scope = ScopeServiceEnum.Transient) where TImplementation : class, TService where TService : class
 {
     this.Register <TService>(this._createInstance <TService, TImplementation>, scope);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Internals the register.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="serviceFactory">The service factory.</param>
 /// <param name="scope">The scope.</param>
 protected abstract void InternalRegister <TService>(Func <TService> serviceFactory, ScopeServiceEnum scope) where TService : class;