Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardImplementation();

            Assembly controllerAssembly = Assembly.Load(ControllerAssemblyName);

            services.AddCors();
            services.AddMvc()
            .AddApplicationPart(controllerAssembly)
            .AddControllersAsServices()
            .AddNewtonsoftJson(options => options.GetDefaultMvcJsonOptions(services));

            services.AddRazorPages(options =>
            {
                string pageName = ServerSettings.ServerConfig?.DefaultRoute ?? "/Index";
                options.Conventions.AddPageRoute(pageName, "");
            });

            //Check whether Submodel Service Provider exists and bind it to the Submodel-Services-Controller
            services.AddTransient(ctx =>
            {
                ISubmodelServiceProvider submodelServiceProvider = ctx
                                                                   .GetRequiredService <ISubmodelRepositoryServiceProvider>()
                                                                   .GetSubmodelServiceProvider(submodelId);

                return(new SubmodelServices(submodelServiceProvider));
            });

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "BaSyx Submodel Repository HTTP REST-API",
                    Description = "The full description of the generic BaSyx Submodel Repository HTTP REST-API",
                    Contact     = new OpenApiContact {
                        Name = "Constantin Ziesche", Email = "*****@*****.**", Url = new Uri("https://www.bosch.com/de/")
                    },
                    License = new OpenApiLicense {
                        Name = "EPL-2.0", Url = new Uri("https://www.eclipse.org/legal/epl-2.0/")
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{controllerAssembly.GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                if (ResourceChecker.CheckResourceAvailability(controllerAssembly, ControllerAssemblyName, xmlFile, true))
                {
                    c.IncludeXmlComments(xmlPath);
                }
            });
            services.AddSwaggerGenNewtonsoftSupport();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardImplementation();

            Assembly controllerAssembly = Assembly.Load(ControllerAssemblyName);

            services.AddCors();
            services.AddMvc()
            .AddApplicationPart(controllerAssembly)
            .AddControllersAsServices()
            .AddNewtonsoftJson(options => options.GetDefaultMvcJsonOptions(services));
            services.AddRazorPages(options =>
            {
                string pageName = ServerSettings.ServerConfig?.DefaultRoute ?? "/Index";
                options.Conventions.AddPageRoute(pageName, "");
            });


            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo()
                {
                    Version     = "v1",
                    Title       = "BaSyx Registry HTTP REST-API",
                    Description = "The full description of the BaSyx Registry HTTP REST-API",
                    Contact     = new OpenApiContact {
                        Name = "Constantin Ziesche", Email = "*****@*****.**", Url = new Uri("https://www.bosch.com/de/")
                    },
                    License = new OpenApiLicense {
                        Name = "EPL-2.0", Url = new Uri("https://www.eclipse.org/legal/epl-2.0/")
                    }
                });

                var xmlFile = $"{controllerAssembly.GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                if (ResourceChecker.CheckResourceAvailability(controllerAssembly, ControllerAssemblyName, xmlFile, true))
                {
                    c.IncludeXmlComments(xmlPath);
                }
            });
            services.AddSwaggerGenNewtonsoftSupport();
        }