Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940

        public void ConfigureServices(IServiceCollection services)
        {
            //// configure jwt authentication
            //var appSettings = appSettingsSection.Get<AppSettings>();
            //var key = Encoding.ASCII.GetBytes(appSettings.Secret);
            var key = Encoding.ASCII.GetBytes(ClsGlobal.Secret);// default authentication initialization


            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
                };
            });

            services.AddMvc().AddNewtonsoftJson();
            services.AddResponseCompression(opts =>
            {
                opts.EnableForHttps = true;
                opts.MimeTypes      = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/octet-stream" });
            });

            // configure DI for application services
            //***Inject Repository to DataAcess Binders();
            services.AddTransient <ICustomerRepository, CustomerDataAccess>();
            services.AddTransient <IPolicyRepository, PolicyDataAccess>();
            services.AddTransient <IUserRepository, UserDataAccess>();
            services.AddTransient <IExcelRepository, ExcelDataAccess>();



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

            //CORS services
            //PM: Install-Package Microsoft.AspNetCore.Cors -Version 2.2.0
            //https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.0
            services.AddCors();


            //***PM: Install-Package Insight.Database
            SqlInsightDbProvider.RegisterProvider();
            JsonNetObjectSerializer.Initialize();
        }
Пример #2
0
        public void TestJsonNetOverride()
        {
            JsonNetObjectSerializer.Initialize();

            using (var connection = ConnectionWithTransaction())
            {
                connection.ExecuteSql("CREATE PROC ClassAsJsonNetParameter @SubClass [varchar](max) AS SELECT SubClass=@SubClass");

                var input = new JsonClass();
                input.SubClass = new JsonSubClass()
                {
                    Foo = "foo", Bar = 5
                };

                Assert.AreEqual("{\"Foo\":\"foo\",\"Bar\":5}", connection.Single <string>("ClassAsJsonNetParameter", input));

                var result = connection.Query <JsonClass, JsonSubClass>("ClassAsJsonNetParameter", input).First();
                Assert.IsNotNull(result.SubClass);
                Assert.AreEqual(input.SubClass.Foo, result.SubClass.Foo);
                Assert.AreEqual(input.SubClass.Bar, result.SubClass.Bar);
            }
        }