Exemplo n.º 1
0
        public WcfServerConfigurator AddService <TService>(Action <WcfServiceConfigurator <TService> > service)
            where TService : class
        {
            var wcfServiceConfigurator = new WcfServiceConfigurator <TService>();

            service(wcfServiceConfigurator);
            ServiceConfigurations.Add(wcfServiceConfigurator.GetConfiguration());
            return(this);
        }
Exemplo n.º 2
0
        public void AddSetsLogger()
        {
            var plugin         = Substitute.For <IPlugin>();
            var logger         = Substitute.For <ILogger>();
            var configurations = new ServiceConfigurations(logger);

            configurations.Add(plugin);

            plugin.Logger.Should().Be(logger);
        }
Exemplo n.º 3
0
        internal static ServiceConfigurations Find(Configuration config, ILogger logger)
        {
            logger.Information("Loading configuration", PluginDir);

            var configurations = new ServiceConfigurations(logger);

            AddInternalConfigurations();
            AddExternalPlugins();
            return(configurations);

            void AddInternalConfigurations()
            {
                logger.Information("Loading internal service configuration", PluginDir);

                var loader  = Factory.CreateLoader(config, logger).Result;
                var addData = new SetData(loader, logger);

                configurations.Add(new Singletons());
                configurations.Add(addData);
                if (config.EnablePrometheusMonitoring)
                {
                    configurations.Add(new ServiceConfiguration.Prometheus());
                }
                configurations.Add(new HealthCheck(addData, config.EnablePrometheusMonitoring));
                configurations.Add(new Swagger());
                configurations.Add(new ExceptionHandler());
            }

            void AddExternalPlugins()
            {
                if (!config.EnableCustomPlugins)
                {
                    return;
                }

                try
                {
                    logger.Information("Loading external plugins from {path}", PluginDir);
                    var conventions = new ConventionBuilder();
                    conventions.ForTypesDerivedFrom <IPlugin>().Export <IPlugin>().Shared();

                    var containerConfig = new ContainerConfiguration().WithAssembliesInPath(PluginDir, conventions);

                    using var container = containerConfig.CreateContainer();

                    var externalPlugins = container.GetExports <IPlugin>();
                    configurations.AddRange(externalPlugins);
                }
                catch (Exception e)
                {
                    logger.Warning(e, "Error loading plugins from {path}", PluginDir);
                }
            }
        }