コード例 #1
0
        /// <summary>
        /// Initializes a dependency injection container with specified <see cref="IConfiguration"/>.
        /// Registers <see cref="IConfiguration"/> instance to newly created container.
        /// </summary>
        /// <remarks>
        /// <see cref="ILogProvider"/> is not registered to container and is meant to be used during the lifetime of registration and container building process.
        /// <see cref="LegacyUtilities"/> will also be initialized with the given configuration.
        /// </remarks>
        public static ContainerBuilder Create(IConfiguration configuration, ILogProvider logProvider, IPluginScanner pluginScanner)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance(configuration).ExternallyOwned();

            // make properties accessible to modules which are provided with new/unique instance of ContainerBuilder
            containerBuilder.Properties.Add(nameof(IPluginScanner), pluginScanner);
            containerBuilder.Properties.Add(nameof(ILogProvider), logProvider);
            containerBuilder.Properties.Add(nameof(IConfiguration), configuration);

            // this is a patch/mock to provide backward compatibility for all usages of old static classes
            LegacyUtilities.Initialize(configuration);

            return(containerBuilder);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a container with specified <see cref="IConfiguration"/>.
        /// Registers <see cref="IConfiguration"/> instance to newly created container.
        /// <see cref="ILogProvider"/> is not registered and is meant to be used during the lifetime of registration and container building process.
        /// <see cref="LegacyUtilities"/> will also be initialized with the given configuration.
        /// </summary>
        /// <param name="pluginAssemblies">List of assemblies (DLL file paths) that will be used for plugins search when using the <see cref="ContainerBuilderPluginRegistration"/></param>
        public RhetosContainerBuilder(IConfiguration configuration, ILogProvider logProvider, IEnumerable <string> pluginAssemblies)
        {
            this.RegisterInstance(configuration);

            var pluginScanner = new PluginScanner(
                pluginAssemblies,
                PluginScanner.GetCacheFolder(configuration),
                logProvider,
                configuration.GetOptions <PluginScannerOptions>());

            // make properties accessible to modules which are provided with new/unique instance of ContainerBuilder
            this.Properties.Add(nameof(IPluginScanner), pluginScanner);
            this.Properties.Add(nameof(ILogProvider), logProvider);

            // this is a patch/mock to provide backward compatibility for all usages of old static classes
            LegacyUtilities.Initialize(configuration);

            Plugins.Initialize(builder => builder.GetPluginRegistration());
        }