public void Test3()
        {
            Dictionary <string, string> dic = new Dictionary <string, string>()
            {
                { "Plugins:Path", "Test/Plugins" },
                { "Plugins:Xfrogcn.PluginFactory.Test.TestPluginE:ConfigA", "A" },
                { "Plugins:_Share:ConfigB", "B" }, //共享配置
            };

            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(dic)
                         .Build();


            IServiceCollection sc = new ServiceCollection()
                                    .AddPluginFactory(config, typeof(DefaultPluginFactoryConfigTest).Assembly);

            var                  sp      = sc.BuildServiceProvider();
            var                  options = sp.GetRequiredService <PluginFactoryOptions>();
            IPluginLoader        loader  = sp.GetRequiredService <IPluginLoader>();
            DefaultPluginFactory factory = sp.GetRequiredService <IPluginFactory>() as DefaultPluginFactory;

            TestPluginEService pluginEService = sp.GetRequiredService <TestPluginEService>();

            var p2 = factory.GetPlugin <TestPluginE>();

            Assert.Equal(pluginEService, p2.Service);
            Assert.Equal("A", pluginEService.Options.ConfigA);
            Assert.Equal("B", pluginEService.Options.ConfigB);

            // Options变更
            config["Plugins:_Share:ConfigB"] = "B2";
            config.Reload();
            Assert.Equal("B2", pluginEService.Options.ConfigB);
        }
Esempio n. 2
0
 public TestPluginE(IOptionsMonitor <TestPluginEOptions> options, TestPluginEService service) : base(options)
 {
     _service         = service;
     _service.Options = options.CurrentValue;
 }