Example #1
0
 public MaintenanceHub(IFhirService fhirService, ILocalhost localhost, IFhirStoreAdministration fhirStoreAdministration, IFhirIndex fhirIndex, ExamplesSettings examplesSettings)
 {
     _localhost               = localhost;
     _fhirService             = fhirService;
     _fhirStoreAdministration = fhirStoreAdministration;
     _fhirIndex               = fhirIndex;
     _examplesSettings        = examplesSettings;
 }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SparkSettings sparkSettings = new SparkSettings();
            Configuration.Bind("SparkSettings", sparkSettings);

            StoreSettings storeSettings = new StoreSettings();
            Configuration.Bind("StoreSettings", storeSettings);

            ExamplesSettings examplesSettings = new ExamplesSettings();
            Configuration.Bind("ExamplesSettings", examplesSettings);

            services.Configure<ExamplesSettings>(options => Configuration.GetSection("ExamplesSettings").Bind(options));

            services.AddMongoFhirStore(storeSettings);
            services.AddFhir(sparkSettings);

            services.AddSingleton<SparkSettings>(sparkSettings);
            services.AddSingleton<ExamplesSettings>(examplesSettings);

            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
            );

            // services.AddDbContext<ApplicationDbContext>(options =>
            //    options.UseSqlServer(
            //        Configuration.GetConnectionString("DefaultConnection")));

            services.AddDefaultIdentity<ApplicationUser>()
                .AddRoles<IdentityRole>()
                .AddDefaultUI(UIFramework.Bootstrap4)
                .AddEntityFrameworkStores<ApplicationDbContext>();

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

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = "FHIR API", Version = "v1" });
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("RequireAdministratorRole",
                    policy => policy.RequireRole("Admin", "SuperAdmin"));
            });

            services.AddSignalR();
        }
Example #3
0
 public MaintenanceHub(
     IAsyncFhirService fhirService,
     IFhirStoreAdministration fhirStoreAdministration,
     IFhirIndex fhirIndex,
     ExamplesSettings examplesSettings,
     IIndexRebuildService indexRebuildService,
     ILogger <MaintenanceHub> logger,
     IHubContext <MaintenanceHub> hubContext)
 {
     _fhirService             = fhirService;
     _fhirStoreAdministration = fhirStoreAdministration;
     _fhirIndex           = fhirIndex;
     _examplesSettings    = examplesSettings;
     _indexRebuildService = indexRebuildService;
     _logger     = logger;
     _hubContext = hubContext;
 }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Bind to Spark and store settings from appSettings.json
            SparkSettings sparkSettings = new SparkSettings();

            Configuration.Bind("SparkSettings", sparkSettings);
            services.AddSingleton <SparkSettings>(sparkSettings);

            StoreSettings storeSettings = new StoreSettings();

            Configuration.Bind("StoreSettings", storeSettings);

            // Read examples settings from config
            ExamplesSettings examplesSettings = new ExamplesSettings();

            Configuration.Bind("ExamplesSettings", examplesSettings);
            services.Configure <ExamplesSettings>(options => Configuration.GetSection("ExamplesSettings").Bind(options));
            services.AddSingleton <ExamplesSettings>(examplesSettings);

            // Configure cookie policy
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddResponseCompression(options =>
            {
                options.Providers.Add <GzipCompressionProvider>();
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/fhir+json", "application/fhir+xml" });
            });

            // Add database context for user administration
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
                                                         );

            // Add Identity management
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddRoles <IdentityRole>()
            .AddDefaultUI()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddAuthorization();

            // Set up a default policy for CORS that accepts any origin, method and header.
            // only for test purposes.
            services.AddCors(options =>
                             options.AddDefaultPolicy(policy =>
            {
                policy.AllowAnyOrigin();
                policy.AllowAnyMethod();
                policy.AllowAnyHeader();
            }));

            // Sets up the MongoDB store
            services.AddMongoFhirStore(storeSettings);

            // AddFhir also calls AddMvcCore
            services.AddFhir(sparkSettings);

            services.AddTransient <ServerMetadata>();

            // AddMvc needs to be called since we are using a Home page that is reliant on the full MVC framework
            services.AddMvc(options =>
            {
                options.InputFormatters.RemoveType <SystemTextJsonInputFormatter>();
                options.OutputFormatters.RemoveType <SystemTextJsonOutputFormatter>();
                options.EnableEndpointRouting = false;
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Spark API", Version = "v1"
                });
            });

            services.AddSignalR();
        }
Example #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Bind to Spark and store settings from appSettings.json
            SparkSettings sparkSettings = new SparkSettings();

            Configuration.Bind("SparkSettings", sparkSettings);
            services.AddSingleton <SparkSettings>(sparkSettings);

            StoreSettings storeSettings = new StoreSettings();

            Configuration.Bind("StoreSettings", storeSettings);

            // Read examples settings from config
            ExamplesSettings examplesSettings = new ExamplesSettings();

            Configuration.Bind("ExamplesSettings", examplesSettings);
            services.Configure <ExamplesSettings>(options => Configuration.GetSection("ExamplesSettings").Bind(options));
            services.AddSingleton <ExamplesSettings>(examplesSettings);

            // Configure cookie policy
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddResponseCompression(options =>
            {
                options.Providers.Add <GzipCompressionProvider>();
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/fhir+json", "application/fhir+xml" });
            });

            // Add database context for user administration
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
                                                         );

            // Add Identity management
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddRoles <IdentityRole>()
            .AddDefaultUI()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddAuthorization();

            // Set up a default policy for CORS that accepts any origin, method and header.
            // only for test purposes.
            services.AddCors(options =>
                             options.AddDefaultPolicy(policy =>
            {
                policy.AllowAnyOrigin();
                policy.AllowAnyMethod();
                policy.AllowAnyHeader();
            }));

            // Sets up the MongoDB store
            services.AddMongoFhirStore(storeSettings);

            // AddFhir also calls AddMvcCore
            services.AddFhir(sparkSettings);

            services.AddTransient <ServerMetadata>();

            // AddMvc needs to be called since we are using a Home page that is reliant on the full MVC framework
            services.AddMvc(options =>
            {
                options.InputFormatters.RemoveType <SystemTextJsonInputFormatter>();
                options.OutputFormatters.RemoveType <SystemTextJsonOutputFormatter>();
                options.EnableEndpointRouting = false;
            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Spark API", Version = "v1"
                });
            });

            services.AddSignalR();

            // Make validation errors to be returned as application/json or application/xml
            // instead of application/problem+json and application/problem+xml.
            // (https://github.com/FirelyTeam/spark/issues/282)
            services.Configure <ApiBehaviorOptions>(options =>
            {
                var defaultInvalidModelStateResponseFactory = options.InvalidModelStateResponseFactory;
                options.InvalidModelStateResponseFactory    = context =>
                {
                    var actionResult = defaultInvalidModelStateResponseFactory(context) as ObjectResult;
                    if (actionResult != null)
                    {
                        actionResult.ContentTypes.Clear();
                        foreach (var mediaType in ResourceJsonOutputFormatter.JsonMediaTypes
                                 .Concat(ResourceXmlOutputFormatter.XmlMediaTypes))
                        {
                            actionResult.ContentTypes.Add(mediaType);
                        }
                    }
                    return(actionResult);
                };
            });
        }