Пример #1
0
        private IServiceProvider InitializeAutofac(IServiceCollection services)
        {
            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor =
                new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            var children                 = this._configuration.GetSection("Caching").GetChildren();
            var cachingConfiguration     = children.ToDictionary(child => child.Key, child => TimeSpan.Parse(child.Value));
            var emailsSettings           = _configuration.GetSection("EmailsSettings").Get <EmailsSettings>();
            var azureBlobStorageSettings =
                _configuration.GetSection("AzureBlobStorageSettings").Get <AzureBlobStorageSettings>();
            var memoryCache = serviceProvider.GetService <IMemoryCache>();

            return(ApplicationStartup.Initialize(
                       services,
                       this._configuration[TreesConnectionString],
                       new MemoryCacheStore(memoryCache, cachingConfiguration),
                       null,
                       null,
                       emailsSettings,
                       azureBlobStorageSettings,
                       _logger,
                       executionContextAccessor,
                       null));
        }
Пример #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllers(c =>
            {
                c.Conventions.Add(new ApiExplorerGroupPerVersionConvention());
            })
            .AddNewtonsoftJson(opt =>
            {
                opt.SerializerSettings.ContractResolver = new JsonApiContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
                opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            services
            .AddVersioningSystem()
            .AddSwaggerDocumentation()
            .AddProblemDetailsMiddleware()
            .AddHealthChecks();

            services.AddCors(options =>
            {
                options.AddPolicy("EnableCORS", builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().Build();
                });
            });

            services.Configure <ProjectConfig>(Configuration.GetSection("ProjectConfig"));

            return(ApplicationStartup.Initialize(
                       services, Configuration));
        }
Пример #3
0
        public async Task BeforeEachTest()
        {
            const string connectionStringEnvironmentVariable =
                "ASPNETCORE_SampleProject_IntegrationTests_ConnectionString";

            ConnectionString = Environment.GetEnvironmentVariable(connectionStringEnvironmentVariable);
            if (ConnectionString == null)
            {
                throw new ApplicationException(
                          $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}");
            }

            await using var sqlConnection = new SqlConnection(ConnectionString);

            await ClearDatabase(sqlConnection);

            EmailsSettings = new EmailsSettings {
                FromAddressEmail = "*****@*****.**"
            };

            EmailSender = Substitute.For <IEmailSender>();

            ApplicationStartup.Initialize(
                new ServiceCollection(),
                ConnectionString,
                new CacheStore(),
                EmailSender,
                EmailsSettings,
                runQuartz: false);
        }
Пример #4
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMemoryCache();

            services.AddSwaggerDocumentation();

            services.AddProblemDetails(x =>
            {
                x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex));
            });


            services.AddHttpContextAccessor();
            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            var children             = this._configuration.GetSection("Caching").GetChildren();
            var cachingConfiguration = children.ToDictionary(child => child.Key, child => TimeSpan.Parse(child.Value));
            var emailsSettings       = _configuration.GetSection("EmailsSettings").Get <EmailsSettings>();
            var memoryCache          = serviceProvider.GetService <IMemoryCache>();

            return(ApplicationStartup.Initialize(
                       services,
                       this._configuration[OrdersConnectionString],
                       new MemoryCacheStore(memoryCache, cachingConfiguration),
                       null,
                       emailsSettings,
                       _logger,
                       executionContextAccessor));
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMemoryCache();

            services.AddSwaggerDocumentation();

            //services.AddMediatR(typeof(RegisterCustomerCommandHandler).GetTypeInfo().Assembly);

            services
            .AddDbContext <OrdersContext>(options =>
            {
                options
                .ReplaceService <IValueConverterSelector, StronglyTypedIdValueConverterSelector>()

                .UseSqlServer(this._configuration[OrdersConnectionString]);
            });

            services.AddProblemDetails(x =>
            {
                x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex));
            });

            var children             = this._configuration.GetSection("Caching").GetChildren();
            var cachingConfiguration = children.ToDictionary(child => child.Key, child => TimeSpan.Parse(child.Value));

            ApplicationStartup.Initialize(
                services,
                this._configuration[OrdersConnectionString],
                cachingConfiguration);
        }
Пример #6
0
        public static void Start()
        {
            ApplicationStartup.Initialize();
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                var register = new SerializerRegister();
                container.Register <IPresentationUserSettings, IUserSettings, ICoreUserSettings, BatchUserSettings>(LifeStyle.Transient);

                container.AddRegister(x =>
                {
                    x.FromType <CoreRegister>();
                    x.FromType <OSPSuite.Core.CoreRegister>();
                    x.FromType <BatchRegister>();
                    x.FromType <InfrastructureRegister>();
                    x.FromType <SBMLImportRegister>();
                    x.FromInstance(new PresentationRegister(false));
                    x.FromInstance(register);
                });
                register.PerformMappingForSerializerIn(container);


                container.Register <IJournalDiagramManagerFactory, BatchJournalDiagramManagerFactory>();
                container.Register <IDiagramModelToXmlMapper, BatchDiagramModelToXmlMapper>(LifeStyle.Singleton);
                container.Register <IDiagramModel, BatchDiagramModel>(LifeStyle.Singleton);
            }
            setupDimensions(container);
            setupCalculationMethods(container);
        }
Пример #7
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllers()
            .AddNewtonsoftJson(opt =>
            {
                opt.SerializerSettings.ContractResolver = new JsonApiContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
                opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });


            services
            .AddVersioningSystem()
            .AddSwaggerDocumentation()
            .AddProblemDetailsMiddleware()
            .AddHealthChecks();

            services.Configure <InterestRateApiQueryConfig>(Configuration.GetSection("InterestRateApiQueryConfig"));
            services.Configure <ProjectConfig>(Configuration.GetSection("ProjectConfig"));

            services.AddScoped <IInterestRateQueryApi, InterestRateQueryApi>();

            return(ApplicationStartup.Initialize(
                       services, Configuration));
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddHttpContextAccessor();
            services.AddDbContext <LocationContext>(options =>
            {
                var conn = Configuration.GetConnectionString("DefaultConnection");
                options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"),
                                  npSqlOptions =>
                {
                    npSqlOptions.CommandTimeout(3300);
                });
            });
            services.AddSwaggerDocumentation();
            services.AddProblemDetails(x =>
            {
                // x.Map<InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex));
            });

            services.AddHttpContextAccessor();
            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            services.AddAutoMapper(cfg =>
            {
                cfg.AddMaps(AppDomain.CurrentDomain.GetAssemblies());
            }, AppDomain.CurrentDomain.GetAssemblies());

            return(ApplicationStartup.Initialize(services, executionContextAccessor));
        }
Пример #9
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers()
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            });

            services.CorsConfigure();
            services.ConfigureProblemDetails(_env.IsProduction());
            services.AddSwaggerDocumentation();

            services.AddHttpContextAccessor();
            services.AuthenticationConfigure(_configuration.GetSection("AppSettings").GetSection("JWT").GetValue <string>("SecretKey"));

            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            return(ApplicationStartup.Initialize(
                       services,
                       _configuration.GetValue <string>("ConnectionString"),
                       _configuration.GetSection("AppSettings").GetSection("JWT").GetValue <string>("SecretKey"),
                       _configuration.GetSection("AppSettings").GetSection("JWT").GetValue <int>("ExpireMinutes"),
                       executionContextAccessor,
                       _logger
                       ));
        }
Пример #10
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMemoryCache();

            services.AddSwaggerDocumentation();



            services.AddHttpContextAccessor();
            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            var children             = this._configuration.GetSection("Caching").GetChildren();
            var cachingConfiguration = children.ToDictionary(child => child.Key, child => TimeSpan.Parse(child.Value));
            var emailsSettings       = "";
            var memoryCache          = serviceProvider.GetService <IMemoryCache>();

            return(ApplicationStartup.Initialize(
                       services,
                       this._configuration[OrdersConnectionString],
                       new MemoryCacheStore(memoryCache, cachingConfiguration),
                       _logger,
                       executionContextAccessor));
        }
Пример #11
0
 public void ConfigureContainer(ContainerBuilder builder)
 {
     // Register your own things directly with Autofac, like:
     ApplicationStartup.Initialize(
         builder,
         this._configuration[OrdersConnectionString],
         this._configuration[ConnectionKrakenString]);
 }
Пример #12
0
 private static void Main(string[] args)
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     ApplicationStartup.Initialize();
     WindowsFormsSettings.SetDPIAware();
     Application.Run(IoC.Resolve <ITestPresenter>().View as Form);
 }
Пример #13
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ApplicationStartup.Initialize();

            var applicationConfugration = new ApplicationConfiguration();

            Application.Run(IoC.Resolve <ITestPresenter>().View as Form);
        }
Пример #14
0
 public static void InitializeOnce()
 {
     try
     {
         _container = ApplicationStartup.Initialize();
     }
     catch (System.Reflection.ReflectionTypeLoadException e)
     {
         e.LoaderExceptions?.Each(x => Console.WriteLine(e.FullMessage()));
         throw;
     }
 }
Пример #15
0
        public ApplicationFixture()
        {
            const string connectionStringEnvironmentVariable =
                "ASPNETCORE_TreeOfAKind_IntegrationTests_ConnectionString";

            ConnectionString = Environment.GetEnvironmentVariable(connectionStringEnvironmentVariable);
            if (ConnectionString == null)
            {
                throw new ApplicationException(
                          $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}");
            }

            using var sqlConnection = new SqlConnection(ConnectionString);

            ClearDatabase(sqlConnection);

            EmailsSettings = new EmailsSettings {
                FromAddressEmail = "*****@*****.**"
            };

            AzureBlobStorageSettings = new AzureBlobStorageSettings
            {
                ConnectionString = "someConnectionString",
                Metadata         = new Dictionary <string, string>
                {
                    { "IntegrationTesting", "true" }
                }
            };

            EmailSender = Substitute.For <IEmailSender>();

            FileSaver = Substitute.For <IFileSaver>();

            UserAuthIdProvider = Substitute.For <IUserAuthIdProvider>();

            ExecutionContext = new ExecutionContextMock();

            ApplicationStartup.Initialize(
                new ServiceCollection(),
                ConnectionString,
                new CacheStore(),
                EmailSender,
                FileSaver,
                EmailsSettings,
                AzureBlobStorageSettings,
                Logger.None,
                ExecutionContext,
                UserAuthIdProvider,
                runQuartz: false);
        }
Пример #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(logging => {
                logging.ClearProviders();
                logging.AddConsole();
                logging.AddDebug();
            });

            services.AddControllers();

            services.AddEndpointsApiExplorer();
            services.AddSwaggerGen();

            // todo: configure as env params!
            var allowedAddresses = new string[] {
                "http://localhost:3000",
                "http://localhost:10003",
            };

            services.AddCors(options =>
            {
                var builder = new CorsPolicyBuilder()
                              .WithOrigins(allowedAddresses)
                              .AllowAnyHeader()
                              .AllowAnyMethod()
                              .AllowCredentials();

                options.AddPolicy(CorsPolicy, builder.Build());
            });

            services.Configure <GzipCompressionProviderOptions>(options =>
                                                                options.Level = CompressionLevel.Optimal);

            services.AddResponseCompression();

            // todo: MediaTr IoC to infra layer!
            services.AddMediatR(Assembly.GetExecutingAssembly(),
                                typeof(GetBirdsQuery).Assembly,
                                typeof(MongoConnection).Assembly,
                                typeof(Bird).Assembly
                                );

            var appSettings = _configuration.GetSection(nameof(AppSettings)).Get <AppSettings>();
            var sp          = ApplicationStartup.Initialize(services, appSettings, new InitializeOptions());

            services.AddHealthChecks()
            .AddCheck <FlickrHealthCheck>("flickr-access")
            .AddProcessAllocatedMemoryHealthCheck(200 * 1000 * 1000);
        }
Пример #17
0
 private static void Main(string[] args)
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     try
     {
         ApplicationStartup.Initialize();
         IoC.Container.Register <MoBiApplication, MoBiApplication>(LifeStyle.Singleton);
         IoC.Resolve <MoBiApplication>().Run(args);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ExceptionMessageWithStackTrace(), "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #18
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //   WindowsFormsSettings.SetDPIAware();
            WindowsFormsSettings.TouchUIMode = TouchUIMode.False;

            try
            {
                ApplicationStartup.Initialize(LogLevel.Debug);
                IoC.Resolve <PKSimApplication>().Run(args);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ExceptionMessageWithStackTrace(), "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #19
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson(options =>
                                                        options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                                                        );

            services.AddSwaggerDocumentation();

            services.AddProblemDetails(x =>
            {
                x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex));
            });

            return(ApplicationStartup.Initialize(
                       services,
                       _configuration[EmployeesConnectionString],
                       _logger));
        }
Пример #20
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            WindowsFormsSettings.SetDPIAware();
            WindowsFormsSettings.SetPerMonitorDpiAware();
            WindowsFormsSettings.TouchUIMode = TouchUIMode.False;
            try
            {
                ApplicationStartup.Initialize(registrationAction);
                IoC.Container.Register <MoBiApplication, MoBiApplication>(LifeStyle.Singleton);
                IoC.Resolve <MoBiApplication>().Run(args);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ExceptionMessageWithStackTrace(), "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #21
0
        static int Main(string[] args)
        {
            ApplicationStartup.Initialize();

            Parser.Default.ParseArguments <QualificationRunCommand>(args)
            .WithParsed(startCommand)
            .WithNotParsed(err => _valid = false);

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }

            if (!_valid)
            {
                return((int)ExitCodes.Error);
            }

            return((int)ExitCodes.Success);
        }
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllers()
            .AddNewtonsoftJson(opt =>
            {
                opt.SerializerSettings.ContractResolver = new JsonApiContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
                opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

            services
            .AddVersioningSystem()
            .AddSwaggerDocumentation()
            .AddHealthChecks();

            return(ApplicationStartup.Initialize(
                       services, Configuration));
        }
Пример #23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddSwaggerDocumentation();

            services.AddProblemDetails(x =>
            {
                x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex));
            });



            // TODO: Refactor - move to specific class (extension method)
            services.AddHealthChecks()
            .AddSqlServer(connectionString: this.Configuration.GetConnectionString(QuestionsConnectionString),
                          name: "sqlserver",
                          failureStatus: HealthStatus.Unhealthy,
                          timeout: TimeSpan.FromSeconds(5));


            services.AddHttpContextAccessor();
            var serviceProvider = services.BuildServiceProvider();

            IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>());

            var emailsSettings = Configuration.GetSection("EmailsSettings").Get <EmailsSettings>();

            return(ApplicationStartup.Initialize(
                       services,
                       this.Configuration.GetConnectionString(QuestionsConnectionString),
                       null,
                       emailsSettings,
                       _logger,
                       executionContextAccessor));
        }
Пример #24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(appConfig);
            services.Configure <NotificationTimerConfig>(appConfig.GetSection("NotificationTimerConfiguration"));
            services.Configure <MailConfig>(appConfig.GetSection("MailSettings"));

            // Add swagger documentation
            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
                {
                    Title       = "Elekta Coding Challenge API(Appointments)",
                    Version     = "v1",
                    Description = "Elekta Coding Challenge using .NET Core REST API CQRS implementation with raw SQL (Dapper) and DDD in line with Clean Architecture."
                });
            });

            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                options.JsonSerializerOptions.DictionaryKeyPolicy  = JsonNamingPolicy.CamelCase;
                options.JsonSerializerOptions.Converters.Add(new TimeSpanConverter());
            });   // json data output serialisation setings

            var connString = appConfig.GetValue <string>(ConnectionStringName);


            services.AddHttpContextAccessor();

            ApplicationStartup.Initialize(services, connString);


            services.AddControllers();

            // set this at the bottom of the page after all services are added.
            serviceCollection = services;
        }
Пример #25
0
 public static void InitializeOnce()
 {
     _container = ApplicationStartup.Initialize();
 }
 static SimulationLoader()
 {
     ApplicationStartup.Initialize();
 }
Пример #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            ApplicationStartup.Initialize(services, Configuration);
        }
Пример #28
0
 private void ConfigureServices(IServiceCollection services)
 {
     ServiceProvider = ApplicationStartup.Initialize(services);
 }
Пример #29
0
 public static void InitializeOnce(ApiConfig apiConfig)
 {
     Container = ApplicationStartup.Initialize(apiConfig);
 }