Example #1
0
 public async Task SeedData(bool isDevelopmentEnvironment)
 {
     if (isDevelopmentEnvironment)
     {
         await DbSeeding.ScheduleMessageTemplateSeeding(_scheduleMessageTemplateRepository);
     }
 }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();
            app.UseSwaggerUI(x =>
            {
                x.SwaggerEndpoint("/swagger/v1/swagger.json", "CRUD");
                x.RoutePrefix = "Documentation";
                x.DisplayRequestDuration();
                x.EnableFilter();
            });
            DbSeeding.SeedDb(app);  //Seed User
        }
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// Note: the order matters to ensure which framework will be called first.
        /// </summary>
        /// <param name="app">
        /// The service which is proveded
        /// </param>
        /// <param name="seeder">
        /// Initialize the database, in case no entry exists.
        /// </param>
        /// <param name="loggerFactory">
        /// Logs the process of the service, in case of an error.
        /// </param>
        /// <param name="environment">
        /// Environment variable in order to ensure whether it is a development environment or a runtime environment.
        /// </param>
        public void Configure(IApplicationBuilder app,
                              DbSeeding seeder,
                              ILoggerFactory loggerFactory,
                              IHostingEnvironment environment)
        {
            //Only while debuging
            if (environment.IsDevelopment())
            {
                loggerFactory.AddConsole(Configuration.GetSection("Logging"));
                loggerFactory.AddDebug(LogLevel.Information);
                loggerFactory.AddDebug();
                //More presise error information
                app.UseDeveloperExceptionPage();
            }

            //The service is using the Identity framework.
            app.UseIdentity();

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();

            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUi();

            //Should be one of the last calls.
            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Index", action = "API" });
            });

            //Last call because synchronised
            seeder.EnsureSeedData().Wait();
        }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string clientId = Configuration.GetSection("Google").Get <Settings.GoogleSettings>().ClientId;

            services
            .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(jwt => jwt.UseGoogle(clientId: clientId));

            services.AddHealthChecks();
            services.AddControllers();

            services.AddSingleton <IDocumentStore>(ctx =>
            {
                var dbConfig = Configuration.GetSection("Database").Get <Settings.DatabaseSettings>();

                var store = new DocumentStore
                {
                    Urls     = dbConfig.Urls,
                    Database = dbConfig.DatabaseName
                };

                if (!string.IsNullOrWhiteSpace(dbConfig.CertPath))
                {
                    store.Certificate = new X509Certificate2(dbConfig.CertPath, dbConfig.CertPass);
                }

                var http = ctx.GetRequiredService <IHttpContextAccessor>();

                store.OnBeforeStore += (sender, e) =>
                {
                    var identity = http.HttpContext?.User.Identity;
                    if (identity == null)
                    {
                        return;
                    }

                    if (e.Session.GetChangeVectorFor(e.Entity) == null)
                    {
                        e.DocumentMetadata["Created-By"] = identity.Name;
                    }
                    e.DocumentMetadata["Modified-By"] = identity.Name;
                };

                store.OnSessionCreated += (sender, args) =>
                {
                    // args.Session
                    /* track session creation */
                };

                store.OnSessionDisposing += (sender, args) =>
                {
                    // args.Session
                    /* track session disposal */
                };

                store.Initialize();

                IndexCreation.CreateIndexes(typeof(Startup).Assembly, store);

                DbSeeding dbs = new DbSeeding();
                dbs.Setup(store, Configuration.GetSection("SuperAdmin").Get <string>());

                return(store);
            });

            services.AddMediatR(typeof(Startup));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingPipelineBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(AuthPipelineQueryBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(AuthPipelineCommandBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidatorPipelineBehavior <,>));

            services.AddScoped <Authenticator>();

            var entryAssembly = Assembly.GetAssembly(typeof(Startup));

            services.Scan(
                x =>
            {
                x.FromAssemblies(entryAssembly)
                .AddClasses(classes => classes.AssignableTo(typeof(IAuth <>)))
                .AddClasses(classes => classes.AssignableTo(typeof(IAuth <,>)))
                .AsImplementedInterfaces()
                .WithScopedLifetime();
            });

            services.Scan(
                x =>
            {
                x.FromAssemblies(entryAssembly)
                .AddClasses(classes => classes.AssignableTo(typeof(AbstractValidator <>)))
                .AsImplementedInterfaces()
                .WithScopedLifetime();
            });

            services.AddTransient <IMailer, Mailer>();

            services.AddProblemDetails(ConfigureProblemDetails);

            services.AddSwaggerDocument(settings =>
            {
                settings.Title = App.Title;
            });

            services.AddHttpContextAccessor();
        }
 protected override void Seed(RoshamboContext context)
 {
     Debug.WriteLine("In CustomCreateDbIfNotExist.");
     DbSeeding.SeedContext(context);
     base.Seed(context);
 }