Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <JobBoardContext>(options =>
                                                    options.UseMySQL(Configuration["JobBoardConnection:ConnectionString"],
                                                                     b => b.MigrationsAssembly("jobboard.backend"))
                                                    .ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)));

            // Repositories
            services.AddScoped <ISkillRepository, SkillRepository>();
            services.AddScoped <IJobRepository, JobRepository>();
            services.AddScoped <IWorkerService, WorkerService>();

            AutoMappingConfiguration.Configure();

            // Enable Cors
            services.AddCors();

            // Add MVC services to the services container.
            services.AddMvc()
            .AddJsonOptions(opts =>
            {
                // Force Camel Case to JSON
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
        }
Example #2
0
        public override void PostInitialize()
        {
            RegisterFilters(HttpConfiguration);

            //autoMapping
            var autoMappingConfiguration = new AutoMappingConfiguration();

            autoMappingConfiguration.CreateMaps();

            //默认使用Newtonsoft序列化
            var formatter = HttpConfiguration.Formatters.JsonFormatter;

            formatter.SerializerSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            //解决json序列化时,Json返回日期带T无法格式化的问题
            HttpConfiguration.Formatters.JsonFormatter
            .SerializerSettings
            .Converters.Add(
                new IsoDateTimeConverter
            {
                DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
            });
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            AutoMappingConfiguration.Configuration();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // fix lỗi
            HttpConfiguration config = GlobalConfiguration.Configuration;

            config.Formatters.JsonFormatter
            .SerializerSettings
            .ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
        }
 public static void UseAutoMappings <TClassInDomainObjectAssembly, TClassInMappingAssembly>()
 {
     MappingConfiguration =
         AutoMappingConfiguration.CreateWithOverrides <TClassInDomainObjectAssembly, TClassInMappingAssembly>();
 }