Exemple #1
0
        public void RegisterType <T>(DiInstanceTypeEnum diInstanceTypeEnum)
        {
            switch (diInstanceTypeEnum)
            {
            case DiInstanceTypeEnum.SingleInstance:
                this.containerBuilder.RegisterType <T>().SingleInstance();
                break;

            case DiInstanceTypeEnum.InstancePerLifetimeScope:
                this.containerBuilder.RegisterType <T>().InstancePerLifetimeScope();
                break;

            case DiInstanceTypeEnum.InstancePerLifetimeScopeWithSingleInstance:
                this.containerBuilder.RegisterType <T>().InstancePerLifetimeScope().SingleInstance();
                break;

            case DiInstanceTypeEnum.InstancePerRequest:
                this.containerBuilder.RegisterType <T>().InstancePerRequest();
                break;

            default:
                this.containerBuilder.RegisterType <T>();
                break;
            }
        }
        public void RegisterWithParameterType <T, P>(DiInstanceTypeEnum instanceTypeEnum = DiInstanceTypeEnum.NewInstancePerRequest)
        {
            switch (instanceTypeEnum)
            {
            case DiInstanceTypeEnum.SingleInstance:
                containerBuilder.RegisterType <T>().WithParameter(
                    new TypedParameter(typeof(P), null)
                    ).SingleInstance();
                break;

            case DiInstanceTypeEnum.InstancePerLifetimeScope:
                containerBuilder.RegisterType <T>().WithParameter(
                    new TypedParameter(typeof(P), null)
                    ).InstancePerLifetimeScope();
                break;

            case DiInstanceTypeEnum.InstancePerLifetimeScopeWithSingleInstance:
                containerBuilder.RegisterType <T>().WithParameter(
                    new TypedParameter(typeof(P), null)
                    ).InstancePerLifetimeScope().SingleInstance();
                break;

            case DiInstanceTypeEnum.InstancePerRequest:
                containerBuilder.RegisterType <T>().WithParameter(
                    new TypedParameter(typeof(P), null)
                    ).InstancePerRequest();
                break;

            default:
                containerBuilder.RegisterType <T>().WithParameter(
                    new TypedParameter(typeof(P), null)
                    );
                break;
            }
        }