Esempio n. 1
0
        public void RegisterType <T, U>(RegistrationLifetime registrationLifetime = RegistrationLifetime.InstancePerResolve) where U : T
        {
            _container.RegisterType <T, U>(registrationLifetime);

            JsonPropertyConverterRepository.TryOverride <T, U>();
            JsonPropertiesConverterRepository.TryOverride <T, U>();
        }
Esempio n. 2
0
        public virtual void RegisterType <TRegistered, TTo>(RegistrationLifetime registrationLifetime = RegistrationLifetime.InstancePerResolve) where TTo : TRegistered
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Cannot update container after it was already initialized");
            }

            Action <ContainerBuilder> registrationAction;

            switch (registrationLifetime)
            {
            case RegistrationLifetime.InstancePerResolve:
                registrationAction = builder => builder.RegisterType <TTo>().As <TRegistered>();
                break;

            case RegistrationLifetime.InstancePerApplication:
                registrationAction = builder => builder.RegisterType <TTo>().As <TRegistered>().SingleInstance();
                break;

            default:
                throw new NotSupportedException("This operation is not supported");
            }

            JsonPropertyConverterRepository.TryOverride <TRegistered, TTo>();
            JsonPropertiesConverterRepository.TryOverride <TRegistered, TTo>();

            registrationAction(_containerBuilder);
            RegistrationActions.Add(registrationAction);
        }