// This method gets called by the runtime. Use this method to add services to the container.
        //public IServiceProvider ConfigureServices(IServiceCollection services)
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            // TODO: enable API versioning when Microsoft.AspNetCore.Mvc.Versioning package supports .NET Core 3.0
            //services.AddApiVersioning();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            // bind the configuration to our SolarConfig configuration class
            var solarConfig = new SolarConfig();

            Configuration.Bind(solarConfig);

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1.0", new OpenApiInfo
                {
                    Title       = GetTitle(),
                    Version     = GetVersion(),
                    Description = "A simple API for retrieving measurements from Solar sites",
                    License     = new OpenApiLicense
                    {
                        Name = "Licensed under MIT Licence",
                        Url  = new Uri("http://opensource.org/licenses/MIT"),
                    }
                });

                c.DescribeAllEnumsAsStrings();
                c.DescribeStringEnumsInCamelCase();

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            // DI
            services.AddSingleton(solarConfig);
            services.AddScoped <ISolarMeasurementsService, SolarMeasurementsService>();
            services.AddScoped <ISolarMeasurementsRepository, InfluxDbRepository>();
            services.AddScoped <IInfluxDbClient>((_) =>
                                                 new InfluxDbClient("http://yourinfluxdb.com:8086/",
                                                                    "ciprian", "", InfluxDbVersion.Latest));

            // Add custom provider
            //var container = new MainContainerFactory(services).CreateServiceProvider();
            //return container;

//            return WindsorRegistrationHelper.CreateServiceProvider(
//                new WindsorContainer(), services);
        }
示例#2
0
 public InfluxDbRepository(IInfluxDbClient dbClient, SolarConfig config)
 {
     _dbClient = dbClient ?? throw new ArgumentNullException(nameof(dbClient));
     _config   = config ?? throw new ArgumentNullException(nameof(config));
 }