Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LightInjectServiceProviderFactory"/> class.
        /// </summary>
        /// <param name="options">The <see cref="ContainerOptions"/> to be used when creating the <see cref="ServiceContainer"/>.</param>
        public LightInjectServiceProviderFactory(ContainerOptions options)
        {
            var clonedOptions = options.Clone();

            clonedOptions.WithMicrosoftSettings();
            containerFactory = () => new ServiceContainer(clonedOptions);
        }
        /// <summary>
        /// Configures the <paramref name="hostBuilder"/> to use LightInject as the service container.
        /// </summary>
        /// <param name="hostBuilder">The target <see cref="IWebHostBuilder"/>.</param>
        /// <param name="options">The <see cref="ContainerOptions"/> to be used when creating the <see cref="IServiceContainer"/>.</param>
        /// <returns>The <see cref="IWebHostBuilder"/> configured to use LightInject.</returns>
        public static IWebHostBuilder UseLightInject(this IWebHostBuilder hostBuilder, ContainerOptions options)
        {
            var clonedOptions = options.Clone();

            clonedOptions.WithAspNetCoreSettings();
            return(hostBuilder.ConfigureServices(services => services.AddSingleton <IServiceProviderFactory <IServiceContainer> >(sp => new LightInjectServiceProviderFactory(clonedOptions))));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new <see cref="IServiceProvider"/> from the given <paramref name="serviceCollection"/>.
        /// </summary>
        /// <param name="serviceCollection">The <see cref="IServiceCollection"/> from which to create an <see cref="IServiceProvider"/>.</param>
        /// <param name="options">The <see cref="ContainerOptions"/> to be used when creating the <see cref="ServiceContainer"/>.</param>
        /// <returns>An <see cref="IServiceProvider"/> that is backed by an <see cref="IServiceContainer"/>.</returns>
        public static IServiceProvider CreateLightInjectServiceProvider(this IServiceCollection serviceCollection, ContainerOptions options)
        {
            var clonedOptions = options.Clone();

            clonedOptions.WithMicrosoftSettings();
            var container = new ServiceContainer(clonedOptions);

            return(container.CreateServiceProvider(serviceCollection));
        }