Ejemplo n.º 1
0
        public void ConfigureContainer(ServiceRegistry services)
        {
            // Supports ASP.Net Core DI abstractions
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            //.AddJsonOptions(options => { options.SerializerSettings.MissingMemberHandling = MissingMemberHandling.Error; })
            .AddApplicationPart(typeof(PingController).Assembly);

            var connectionString = Configuration.GetConnectionString(nameof(KatalyeContext));

            services.AddEntityFrameworkNpgsql()
            .AddDbContext <KatalyeContext>(options => options.UseNpgsql(connectionString));

            services.AddSignalR()
            .AddPostgreSql(options => options.Prefix = "katalye:");

            services.AddHangfire(config =>
                                 config.UsePostgreSqlStorage(Configuration.GetConnectionString(nameof(KatalyeContext))));

            services.IncludeRegistry <MediatrRegistry>();
            services.IncludeRegistry <KatalyeRegistry>();
            services.IncludeRegistry <RestEaseRegistry>();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddControllers();

            services.Scan(s =>
            {
                s.TheCallingAssembly();
                s.WithDefaultConventions();
            });

            var assemblies =
                AppDomain
                .CurrentDomain
                .GetAssemblies()
                .Where(s => s.GetName().Name.StartsWith(nameof(Conglomerate)))
                .ToArray();

            // Auto Mapper
            services.AddAutoMapper(assemblies);

            // Services
            services.For <IIngredientService>().Use <IngredientService>();

            // Repositories
            services.For <IIngredientRepository>().Use <IngredientRepository>();

            // Mediatr
            services.AddMediatR(assemblies);

            services.Scan(scanner =>
            {
                foreach (var assembly in assemblies)
                {
                    scanner.Assembly(assembly);
                }

                scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>));
            });

            // For some reason we need to register one of the handlers for Lamar to register all of them
            services.For <IRequestHandler <IngredientGetAll.Query, IList <IngredientGetAll.Ingredient> > >().Use <IngredientGetAll.Handler>();

            services.For <IMediator>().Use <Mediator>().Transient();
            services.For <ServiceFactory>().Use(ctx => ctx.GetInstance);

            // Db Contexts
            services.AddDbContext <SandwichShopContext>(ServiceLifetime.Transient);

            // Hangfire
            services.AddHangfire(configuration => configuration
                                 .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                                 .UseSimpleAssemblyNameTypeSerializer()
                                 .UseRecommendedSerializerSettings()
                                 .UseStorage(new MySqlStorage(Configuration.GetConnectionString("Hangfire"), new MySqlStorageOptions()
            {
                TransactionIsolationLevel  = IsolationLevel.ReadCommitted,
                QueuePollInterval          = TimeSpan.FromSeconds(1),
                JobExpirationCheckInterval = TimeSpan.FromHours(1),
                CountersAggregateInterval  = TimeSpan.FromMinutes(5),
                PrepareSchemaIfNecessary   = true,
                DashboardJobListLimit      = 50000,
                TransactionTimeout         = TimeSpan.FromMinutes(1),
                TablePrefix = "Hangfire"
            })));

            services.AddHangfireServer(options =>
            {
                // Order determines priority
                options.Queues = new[] { JobQueues.API, JobQueues.DEFAULT };
            });

            services.For <IJobFactory>().Use <JobFactory>();
        }
Ejemplo n.º 3
0
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddLogging(config =>
            {
                config.ClearProviders();

                config.AddConfiguration(Configuration.GetSection("Logging"));
                config.AddApplicationInsights();
            });

            //Response Compression - https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-5.0
            services.AddResponseCompression();

            services.AddCors(options =>
            {
                options.AddPolicy("SpecificOrigins",
                                  builder =>
                {
                    builder.WithOrigins("https://tmireact.azurewebsites.net", "https://theminiindex.com", "https://wwww.theminiindex.com", "http://localhost:3000")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddSwaggerGen();

            services.AddDefaultIdentity <IdentityUser>()
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <MiniIndexContext>();

            services.AddHangfire(configuration => configuration
                                 .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                                 .UseSimpleAssemblyNameTypeSerializer()
                                 .UseRecommendedSerializerSettings()
                                 .UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                DisableGlobalLocks           = true
            }));
            services.AddHangfireServer();

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

            services.AddDbContext <MiniIndexContext>(ConfigureEntityFramework);

            string facebookAppId     = Configuration["Authentication:Facebook:AppId"];
            string facebookAppSecret = Configuration["Authentication:Facebook:AppSecret"];

            if (facebookAppId != null && facebookAppSecret != null)
            {
                services.AddAuthentication()
                .AddFacebook(facebookOptions =>
                {
                    facebookOptions.AppId     = facebookAppId;
                    facebookOptions.AppSecret = facebookAppSecret;
                });
            }

            services.AddTransient <IEmailSender, EmailSender>();
            services.Configure <AuthMessageSenderOptions>(Configuration);
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <ITelemetryInitializer, TelemetryEnrichment>();
            services.AddApplicationInsightsTelemetryProcessor <AppInsightsFilter>();
            services.Configure <AzureStorageConfig>(Configuration.GetSection("AzureStorageConfig"));

            services.IncludeRegistry <CoreServices>();
            services.IncludeRegistry <WebAppServices>();
        }