Esempio n. 1
0
        /// <summary>
        /// Registers all objects of a certain type with the bootstrapper
        /// </summary>
        /// <typeparam name="T">Object type</typeparam>
        /// <param name="lifeTime">The life time.</param>
        /// <returns>This</returns>
        public override IBootstrapper RegisterAll <T>(ServiceLifetime lifeTime = ServiceLifetime.Transient)
        {
            var RegisterType = typeof(T);

            foreach (var TempType in GetAvailableTypes().Where(x => IsOfType(x, typeof(T))))
            {
                switch (lifeTime)
                {
                case ServiceLifetime.Scoped:
                    AppContainer.AddScoped(TempType, TempType);
                    AppContainer.AddScoped(RegisterType, TempType);
                    break;

                case ServiceLifetime.Singleton:
                    AppContainer.AddSingleton(TempType, TempType);
                    AppContainer.AddSingleton(RegisterType, TempType);
                    break;

                default:
                    AppContainer.AddTransient(TempType, TempType);
                    AppContainer.AddTransient(RegisterType, TempType);
                    break;
                }
            }
            if (AvailableTypes is null)
            {
                UpdateServiceProvider();
            }
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Registers an object with the bootstrapper
        /// </summary>
        /// <typeparam name="T">Object type</typeparam>
        /// <param name="objectToRegister">The object to register.</param>
        /// <param name="lifeTime">The life time.</param>
        /// <param name="name">The name.</param>
        /// <returns>This</returns>
        public override IBootstrapper Register <T>(T objectToRegister, ServiceLifetime lifeTime = ServiceLifetime.Singleton, string name = "")
        {
            switch (lifeTime)
            {
            case ServiceLifetime.Scoped:
                AppContainer.AddScoped(_ => objectToRegister);
                break;

            case ServiceLifetime.Singleton:
                AppContainer.AddSingleton(_ => objectToRegister);
                break;

            default:
                AppContainer.AddTransient(_ => objectToRegister);
                break;
            }
            if (AvailableTypes is null)
            {
                UpdateServiceProvider();
            }
            return(this);
        }