コード例 #1
0
        public static Provider DalProviderToProvider(DalProvider dalProvider)
        {
            Provider provider = new Provider();

            Mapper.Initialize(Cfg => Cfg.CreateMap <DalProvider, Provider>()
                              .ForMember("ItemFromProviders", opt => new List <ItemFromProvider>()));
            provider = Mapper.Map <DalProvider, Provider>(dalProvider);
            return(provider);
        }
コード例 #2
0
        public static User DalUserToUser(DalUser dalUser)
        {
            User user = new User();
            Shop shop = new Shop();

            Mapper.Initialize(Cfg => Cfg.CreateMap <DalUser, User>()
                              .ForMember("Post", opt => opt.MapFrom(x => shop.Posts.
                                                                    Where(p => p.Name == dalUser.Post).Single())));
            user = Mapper.Map <DalUser, User>(dalUser);
            return(user);
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: albarp/NetCoreCityInfo
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CityInfoContext cityInfoContext)
        {
            AutoMapper.Mapper.Initialize(Cfg =>
            {
                Cfg.CreateMap <Entities.City, Models.CityWithoutPointOfInterestDto>();
                Cfg.CreateMap <Entities.City, Models.CityDto>();
                Cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestDto>();
                Cfg.CreateMap <Models.PointOfInterestForCreationDto, Entities.PointOfInterest>();
                Cfg.CreateMap <Models.PointOfInterestForUpdateDto, Entities.PointOfInterest>();
                Cfg.CreateMap <Entities.PointOfInterest, Models.PointOfInterestForUpdateDto>();
            });

            // Env variables
            // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.1

            // Logging configuration
            // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1
            var logConf = Configuration["Logging:IncludeScopes"];

            // Std logger
            //var logger = loggerFactory.CreateLogger(this.GetType());
            //logger.LogWarning("Warning");



            //var generalLogger = ApplicationLogging.CreateLogger("General");

            //generalLogger.LogCritical("from static");

            // Questi due, invece, ce li mette già il default bilder in program.cs
            //loggerFactory.AddConsole();
            //loggerFactory.AddDebug();

            // Questo è per aggiungere NLog
            loggerFactory.AddNLog(new NLogProviderOptions {
                CaptureMessageTemplates = true, CaptureMessageProperties = true
            });
            NLog.LogManager.LoadConfiguration("nlog.config");

            // Custom static logger
            ApplicationLogging.ConfigureLogger(loggerFactory);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            cityInfoContext.EnsureSeedDataForContext();

            app.UseStatusCodePages();

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    StringBuilder sb = new StringBuilder();

            //    sb.AppendFormat("IsDevelopment: {0} <br/>", env.IsDevelopment());
            //    sb.AppendFormat("IsProduction: {0} <br/>", env.IsProduction());
            //    sb.AppendFormat("IsStaging: {0} ", env.IsStaging());


            //    string output = sb.ToString();

            //    await context.Response.WriteAsync(output);
            //});

            // If stdoutLogEnabled="true" and stdoutLogFile=".\logs\stdout" in web.config, then
            // it gets logged
            Console.WriteLine("Configure called");
        }