Пример #1
0
        public SystemBuilder Use(ServiceUseOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            options.Validate();

            var key    = options.Key;
            var type   = options.ServiceType;
            var policy = options.Policy;

            var registration = new ServiceRegistration(type, options.ImplementationType)
            {
                Instance   = options.Instance,
                Scope      = options.Scope,
                ServiceKey = key
            };

            if (key != null)
            {
                if (policy == ServiceUsePolicy.Replace)
                {
                    if (ServiceContainer.IsRegistered(type, key))
                    {
                        ServiceContainer.Unregister(type, key);
                    }
                }

                ServiceContainer.Register(registration);
            }
            else
            {
                if (policy == ServiceUsePolicy.Replace)
                {
                    if (ServiceContainer.IsRegistered(type))
                    {
                        ServiceContainer.Unregister(type);
                    }
                }

                ServiceContainer.Register(registration);
            }

            return(this);
        }
 public ServiceUseConfigurationProvider()
 {
     Options = new ServiceUseOptions(typeof(TService));
 }
 public ServiceUseWithBindingConfigurationProvider(ServiceUseOptions options)
 {
     this.options = options;
 }
Пример #4
0
 ISystemBuilder ISystemBuilder.Use(ServiceUseOptions options)
 {
     return(Use(options));
 }
Пример #5
0
        public SystemBuilder Use(ServiceUseOptions options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            options.Validate();

            var key = options.Key;
            var type = options.ServiceType;
            var policy = options.Policy;

            var registration = new ServiceRegistration(type, options.ImplementationType) {
                Instance = options.Instance,
                Scope = options.Scope,
                ServiceKey = key
            };

            if (key != null) {
                if (policy == ServiceUsePolicy.Replace) {
                    if (ServiceContainer.IsRegistered(type, key))
                        ServiceContainer.Unregister(type, key);
                }

                ServiceContainer.Register(registration);
            } else {
                if (policy == ServiceUsePolicy.Replace) {
                    if (ServiceContainer.IsRegistered(type))
                        ServiceContainer.Unregister(type);
                }

                ServiceContainer.Register(registration);
            }

            return this;
        }
Пример #6
0
 ISystemBuilder ISystemBuilder.Use(ServiceUseOptions options)
 {
     return Use(options);
 }