コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Set compability mode for mvc
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });
            services.AddSingleton <ITracer>(serviceProvider =>
            {
                var serviceName = Assembly.GetEntryAssembly().GetName().Name;

                Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName + "-http");

                var loggerFactory = new LoggerFactory();
                try
                {
                    // add agenthost and port
                    var config = Jaeger.Configuration.FromEnv(loggerFactory);
                    var tracer = config.GetTracer();

                    GlobalTracer.Register(tracer);
                    return(tracer);
                }
                catch (Exception)
                {
                    Console.WriteLine("Couldn't register logger");
                }

                return(null);
            });
            services.AddHttpClient();
            //services.AddLogging (loggingBuilder => loggingBuilder.AddSerilog (dispose: true));
            services.AddOpenTracing();

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = false,
                    ValidateAudience         = true,
                    ValidateIssuerSigningKey = true,
                    ValidAudience            = "auth",
                    IssuerSigningKey         =
                        new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["AppSettings:Secret"]))
                };
            });

            APIDocumentationInitializer.ApiDocumentationInitializer(services);
            StartupDatabaseInitializer.InitializeDatabase(services);

            services.AddHealthChecks();

            CorsConfig.AddCorsPolicy(services);
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            APIDocumentationInitializer.ApiDocumentationInitializer(services);
            StartupDatabaseInitializer.InitializeDatabase(services);

            services.AddScoped <ISharesRepository, SharesRepository>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <ISharesService, SharesService>();
            CorsConfig.AddCorsPolicy(services);
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Set compability mode for mvc
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            services.AddSingleton <ITracer>(serviceProvider =>
            {
                string serviceName = Assembly.GetEntryAssembly().GetName().Name;

                Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName);

                var loggerFactory = new LoggerFactory();
                try
                {
                    // add agenthost and port
                    var config = Jaeger.Configuration.FromEnv(loggerFactory);
                    var tracer = config.GetTracer();

                    GlobalTracer.Register(tracer);
                    return(tracer);
                }
                catch (System.Exception)
                {
                    System.Console.WriteLine("Couldn't register logger");
                }

                return(null);
            });

            // Add logging
            services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
            services.AddOpenTracing();

            services.AddSingleton <IDatabaseSettings, DatabaseSettings>();
            services.AddTransient <IDatabaseContext, DatabaseContext>();
            services.AddScoped <IModelRepository, ModelRepository>();

            APIDocumentationInitializer.ApiDocumentationInitializer(services);
            StartupDatabaseInitializer.InitializeDatabase(services);

            services.AddHealthChecks();

            CorsConfig.AddCorsPolicy(services);
        }
コード例 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Set compability mode for mvc
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options =>
                            options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
            APIDocumentationInitializer.ApiDocumentationInitializer(services);
            StartupDatabaseInitializer.InitializeDatabase(services);

            services.AddHttpClient();
            services.AddScoped <IAccountsRepository, AccountsRepository>();
            services.AddScoped <IUsersRepository, UsersRepository>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IUsersService, UsersService>();
            services.AddScoped <IAccountService, AccountService>();
            services.AddScoped <IBankService, BankService>();

            CorsConfig.AddCorsPolicy(services);
        }
コード例 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Set compability mode for mvc
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            APIDocumentationInitializer.ApiDocumentationInitializer(services);
            StartupDatabaseInitializer.InitializeDatabase(services);

            services.AddHttpClient();
            services.AddScoped <IUsersService, UsersService>();
            services.AddScoped <IAuthenticationRepository, AuthenticationRepository>();
            services.AddScoped <IPortfolioService, PortfolioService>();
            services.AddScoped <IBankService, BankService>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IAuthenticationService, AuthenticationService>();

            CorsConfig.AddCorsPolicy(services);

            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
        }