Exemplo n.º 1
0
        /// <summary>
        /// Creates the service provider
        /// </summary>
        /// <returns></returns>
        protected virtual SolidProxyServiceProvider CreateServiceProvider()
        {
            var sp = new SolidProxyServiceProvider(ParentScope?.ServiceProvider);

            sp.AddSingleton <ISolidConfigurationScope>(this);
            return(sp);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a new scope
 /// </summary>
 /// <param name="solidProxyServiceProvider"></param>
 public ServiceScope(SolidProxyServiceProvider solidProxyServiceProvider)
 {
     SolidProxyServiceProvider = solidProxyServiceProvider;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a  service provider
        /// </summary>
        /// <returns></returns>
        public IServiceProvider BuildServiceProvider()
        {
            var sp = new SolidProxyServiceProvider();

            foreach (var sd in this)
            {
                switch (sd.Lifetime)
                {
                case ServiceLifetime.Scoped:
                    if (sd.ImplementationInstance != null)
                    {
                        sp.AddScoped(sd.ServiceType, sd.ImplementationInstance);
                    }
                    else if (sd.ImplementationType != null)
                    {
                        sp.AddScoped(sd.ServiceType, sd.ImplementationType);
                    }
                    else if (sd.ImplementationFactory != null)
                    {
                        sp.AddScoped(sd.ServiceType, sd.ImplementationFactory);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    break;

                case ServiceLifetime.Transient:
                    if (sd.ImplementationInstance != null)
                    {
                        sp.AddTransient(sd.ServiceType, sd.ImplementationInstance);
                    }
                    else if (sd.ImplementationType != null)
                    {
                        sp.AddTransient(sd.ServiceType, sd.ImplementationType);
                    }
                    else if (sd.ImplementationFactory != null)
                    {
                        sp.AddTransient(sd.ServiceType, sd.ImplementationFactory);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    break;

                case ServiceLifetime.Singleton:
                    if (sd.ImplementationInstance != null)
                    {
                        sp.AddSingleton(sd.ServiceType, sd.ImplementationInstance);
                    }
                    else if (sd.ImplementationType != null)
                    {
                        sp.AddSingleton(sd.ServiceType, sd.ImplementationType);
                    }
                    else if (sd.ImplementationFactory != null)
                    {
                        sp.AddSingleton(sd.ServiceType, sd.ImplementationFactory);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            // add additional logic
            sp.AddSingleton <IServiceScopeFactory>(o => new ServiceScopeFactory((SolidProxyServiceProvider)o));
            return(sp);
        }