public HttpResponseMessage GetGeocoding([FromUri] GeoLocationParameter parameter) { var validator = new GeoLocationParameterValidator(); var validationResult = validator.Validate(parameter); if (!validationResult.IsValid) { var errorMessage = string.Join("\r\n", validationResult.Errors.Select(e => e.ErrorMessage)); throw new FluentValidation.ValidationException(errorMessage); } var mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap<GeoLocationParameter, GeoLocationParameterDto>(); cfg.CreateMap<GoogleLocateDto, GoogleLocateViewModel>(); cfg.CreateMap<GoogleGeoDataDto, GoogleGeoDataViewModel>(); }); var mapper = mapConfig.CreateMapper(); var geoLocationParameterDto = mapper.Map<GeoLocationParameter, GeoLocationParameterDto>(parameter); var result = this.GoogleGisServer.GetGeocoding(geoLocationParameterDto); var response = mapper.Map<GoogleGeoDataDto, GoogleGeoDataViewModel>(result); return this.GenerateSuccessResponse(parameter, response); }
// TODO: Check if can be changed from dynamic to something else, maybe mapper: like private void ApplyChange(Event @event, bool isNew) { //dynamic dynamic = this; //dynamic.Handle((dynamic)@event); var mapper = new AutoMapper.MapperConfiguration(null).CreateMapper(); mapper.Map(@event, this); if (isNew) _changes.Add(@event); }
/// <summary> /// 取得部門資料. /// </summary> /// <param name="parameter">The SMDepartmentParameterDto.</param> /// <returns>List of SMDepartmentDto</returns> public List<SMDepartmentDto> Get(SMDepartmentParameterDto parameter) { var result = this.DepartmentRepository.Get(parameter); var mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap<SMDepartmentModel, SMDepartmentDto>(); }); var mapper = mapConfig.CreateMapper(); var response = mapper.Map<List<SMDepartmentModel>, List<SMDepartmentDto>>(result); return response; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.WithOrigins("http://localhost:4200"); builder.AllowCredentials(); builder .AllowAnyMethod() .AllowAnyHeader(); })); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(options => { options.ExpireTimeSpan = new TimeSpan(1, 1, 1); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfileConfiguration()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddMvc(); }
Act IObsoleteAction.GetNewAction() { bool uIElementTypeAssigned = false; AutoMapper.MapperConfiguration mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <Act, ActUIElement>(); }); ActUIElement newAct = mapConfig.CreateMapper().Map <Act, ActUIElement>(this); Type currentType = GetActionTypeByElementActionName(this.LinkAction); if (currentType == typeof(ActUIElement)) { // check special cases, where name should be changed. Than at default case - all names that have no change switch (this.LinkAction) { case eLinkAction.Click: newAct.ElementAction = ActUIElement.eElementAction.JavaScriptClick; break; case eLinkAction.Visible: newAct.ElementAction = ActUIElement.eElementAction.IsVisible; break; default: newAct.ElementAction = (ActUIElement.eElementAction)System.Enum.Parse(typeof(ActUIElement.eElementAction), this.LinkAction.ToString()); break; } } newAct.ElementLocateBy = (eLocateBy)((int)this.LocateBy); if (!string.IsNullOrEmpty(this.LocateValue)) { newAct.ElementLocateValue = String.Copy(this.LocateValue); } if (!uIElementTypeAssigned) { newAct.ElementType = eElementType.HyperLink; } newAct.Active = true; return(newAct); }
public async Task GetProductReturnOneProductAsync(int productId) { var dbContextOption = new DbContextOptionsBuilder <Databases.ProductsDbContext>() .UseInMemoryDatabase("GetProductReturnAllProducts"); using var productDbContext = new Databases.ProductsDbContext(dbContextOption.Options); var productProfile = new Profiles.ProductProfile(); var mapperConfig = new AutoMapper.MapperConfiguration(f => f.AddProfile(productProfile)); var mapper = new AutoMapper.Mapper(mapperConfig); var productProvider = new Providers.ProductProvider(productDbContext, null, mapper); var product = await productProvider.GetOneProductsAsync(productId); Assert.True(product.IsSuccess); Assert.NotNull(product.Result); Assert.True(product.Result.Id == productId); Assert.Null(product.ErrorMessage); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddControllersWithViews(); services.AddRazorPages(); // or try transient later services.AddScoped <IFeatureUnitOfWorkRepository, SQLFeatureUnitOfWorkRepository>(); // configuring automapper var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new Helper()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddSingleton <IActionFeedback, ActionFeedback>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //configure automapper for json api var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfile()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); //Configure mvc services.AddMvc(); //connect to mysql database services.AddDbContext <CatScoreContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); // configure Dynamic injection for application services services.AddScoped <ICatScoreService, CatScoreService>(); }
/// <summary> /// 以 google map 地理編碼資訊取得地址/地標 /// </summary> /// <param name="parameter">GeoCodingParameterDto</param> /// <returns>GoogleResponse</returns> public Infrastructure.ClassLibsProxy.Models.GoogleResponse ReverseGeocoding(GeoCodingParameterDto parameter) { var result = new Infrastructure.ClassLibsProxy.Models.GoogleResponse(); using (var googleGeoCoding = new uGIS.GoogleGeocoder(parameter.GeoKey)) { uGIS.GoogleResponse responseColletions = googleGeoCoding.ReverseGeocoding(parameter.Latitude, parameter.Longitude); var mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap<uGIS.GoogleResponse.LocateStatus, Enums.GoogleLocateStatus>(); cfg.CreateMap<uGIS.GoogleLocate, Infrastructure.ClassLibsProxy.Models.GoogleLocate>(); cfg.CreateMap<uGIS.GoogleResponse, Infrastructure.ClassLibsProxy.Models.GoogleResponse>(); }); var mapper = mapConfig.CreateMapper(); result = mapper.Map<uGIS.GoogleResponse, Infrastructure.ClassLibsProxy.Models.GoogleResponse>(responseColletions); } return result; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddApplicationInsightsTelemetry(Configuration); services.AddDbContext <AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("LocalDB"))); services.AddIdentity <ApplicationUser, ApplicationRole>() .AddEntityFrameworkStores <AppDbContext, Int64>() .AddDefaultTokenProviders(); var config = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(new AutoMapperProfileConfiguration())); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddMvc(); }
public UnitTest_UpdatePassword_UserService() { db = new BlogApplicationDbContext(); var configuration = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new UserProfile()); cfg.AddProfile(new TokenProfile()); }); userService = new UserService(db, new AutoMapper.Mapper(configuration)); var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("blogapp!api!this_is@my@secret_key!")); tokenProviderOption = new TokenProviderOption { Audience = "ConsumerUser", Issuer = "BackEnd", SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; }
public static void Configure() { var profiles = from t in System.Reflection.Assembly.GetAssembly(typeof(UserProfile)) .GetTypes() where typeof(AutoMapper.Profile).IsAssignableFrom(t) select(AutoMapper.Profile) Activator.CreateInstance(t); MapperConfiguration = new AutoMapper.MapperConfiguration(cfg => { foreach (var profile in profiles) { cfg.AddProfile(profile); } cfg.CreateMap <string, DateTime?> ().ConvertUsing <Converters.StringToDateTimeConverter> (); cfg.CreateMap <DateTime?, DateTime?>().ConvertUsing <Converters.PersianDateTimeToMiladiConverter>(); }); MapperConfiguration.AssertConfigurationIsValid(); Mapper = new AutoMapper.Mapper(MapperConfiguration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddDbContext <LibraryContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddSingleton <IUnitOfWork, UnitOfWork>(); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile <BookProfile>(); cfg.AddProfile <AuthorProfile>(); cfg.AddProfile <SubjectProfile>(); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddMvc(); }
public void Configuration(IAppBuilder app) { var config = GlobalConfiguration.Configuration; var autoMapperConfigurtaion = new AutoMapper.MapperConfiguration(configuration => { configuration.CreateMap <PatronDto, Patron>(); configuration.CreateMap <Patron, PatronDto>(); }); var builder = new ContainerBuilder(); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterModule <PaintingGalleryModule>(); builder.RegisterInstance(autoMapperConfigurtaion.CreateMapper()); builder.RegisterInstance(System.Configuration.ConfigurationManager.ConnectionStrings["PaintingGalleryConnection"].ConnectionString); var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationContext>(opts => opts.UseSqlServer(Configuration["ConnectionString:CafeApplicationDB"])); services.AddMvc(); services.AddScoped <IRepository <CafeApplication.Data.Models.Consommateur>, Repository <CafeApplication.Data.Models.Consommateur> >(); services.AddScoped <IRepository <CafeApplication.Data.Models.Consommation>, Repository <CafeApplication.Data.Models.Consommation> >(); services.AddScoped <IService, CafeApplication.Service.Service.Service>(); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <IBreuvage, CafeApplication.Data.Models.Consommation>(); cfg.CreateMap <CafeApplication.Data.Models.Consommation, IBreuvage>(); cfg.CreateMap <TypeBoissonViewModel, IBreuvage>(); cfg.CreateMap <IBreuvage, TypeBoissonViewModel>(); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); }
public void Setup() { _AutoMapperConfiguration = new AutoMapper.MapperConfiguration(config => { config.CreateMap <Customer, Customer>(); config.CreateMap <Customer, CustomerDTO>(); config.CreateMap <Address, AddressDTO>(); }); this.AutoMapper = _AutoMapperConfiguration.CreateMapper(); TinyMapper.Bind <Address, Address>(); TinyMapper.Bind <Address, AddressDTO>(); TinyMapper.Bind <Customer, Customer>(); TinyMapper.Bind <Customer, CustomerDTO>(); HigLabo.Core.ObjectMapper.Default.CompilerConfig.ClassPropertyCreateMode = ClassPropertyCreateMode.NewObject; HigLabo.Core.ObjectMapper.Default.CompilerConfig.CollectionElementCreateMode = CollectionElementCreateMode.NewObject; this.Customer = Customer.Create(); this.Address = Address.Create(); this.TC0_Members = TC0_Members.Create(); }
public void Configuration(IAppBuilder app) { var config = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); var autoMapperConfig = new AutoMapper.MapperConfiguration(c => { c.CreateMap <Product, ProductDto>(); c.CreateMap <ProductDto, Product>(); c.CreateMap <ProductForCreation, Product>(); }); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterModule <ProductStoreModule>(); builder.RegisterInstance(autoMapperConfig.CreateMapper()); var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DataContext>(x => x.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var configmap = new AutoMapper.MapperConfiguration(c => { c.AddProfile(new ApplicationProfile()); }); var mapper = configmap.CreateMapper(); services.AddSingleton(mapper); services.AddCors(); services.AddScoped <IUnitOfWork, UnitOfWork>(); services.AddScoped <IBusinessEntityRepository, BusinessEntityRepository>(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <PharmacyContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:Entities"])); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.Configure <ServiceSettings>(Configuration.GetSection("ServiceSettings")); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <CustomerPoco, Customer>(); cfg.CreateMap <Pharmacy.Models.Pocos.OrderPoco, Order>(); cfg.CreateMap <DrugPoco, Drug>(); cfg.CreateMap <ReminderPoco, Reminder>(); cfg.CreateMap <Customer, CustomerPoco>(); cfg.CreateMap <Order, Pharmacy.Models.Pocos.OrderPoco>(); cfg.CreateMap <Drug, DrugPoco>(); cfg.CreateMap <Reminder, ReminderPoco>(); cfg.CreateMap <Shop, ShopPoco>(); cfg.CreateMap <Doctor, DoctorPoco>(); cfg.CreateMap <Practice, PracticePoco>(); cfg.CreateMap <Order, Models.OrderPoco>(); cfg.CreateMap <OrderLine, OrderLinePoco>(); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddAzureAd(options => Configuration.Bind("AzureAd", options)) .AddCookie(); services.AddMvc(); }
// public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <IAuthorizationService, AuthorizationService>(); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddTransient <IUserService, UserService>(); services.AddTransient <IShopService, ShopService>(); services.AddTransient <IPythonServerService, PythonServerService>(); services.AddTransient <IFileWorkService, FileWorkService>(); // services.AddSwaggerGen(c => // { // c.SwaggerDoc("v1", new Info {Title = "Api doc", Version = "V1"}); // }); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfileConfiguration()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext <ApplicationDbContext>(options => { options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection") ); }); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddMemoryCache(); services.AddDbContext <EFContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <ProductViewModel, Product>(); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddSingleton <IProductHandler, ProductHandler>(); services.AddSingleton <IProductQuery, ProductQuery>(); services.AddSingleton <InMemoryProductRepository>(); services.AddSingleton <DatabaseProductRepository>(); services.AddSingleton(factory => { Func <bool, IProductRepository> accesor = IsInMemory => { if (IsInMemory) { return(factory.GetService <InMemoryProductRepository>()); } else { return(factory.GetService <DatabaseProductRepository>()); } }; return(accesor); }); }
public void ConfigureServices(IServiceCollection services) { services.AddAuthorization(options => { options.AddPolicy("SystemMessagingPolicy", policyAdmin => { policyAdmin.RequireClaim("scope", "gofish.messaging"); }); }); services.AddMvc(); services.Configure <ApplicationSettings>(_config.GetSection("ApplicationSettings")); services.AddDbContext <AdvertisingDbContext>(); services.AddTransient <IMessageBroker <Advert>, AdvertMessageBroker>(); services.AddTransient <AdvertRepository, AdvertRepository>(); services.AddTransient <ICommandMediator, CommandMediator>(); services.AddTransient <IAdvertFactory, AdvertFactory>(); services.AddTransient <ILookupCacheProvider, LookupCacheProvider>(); services.AddTransient <ICommandHandler <CreateAdvertCommand, Advert>, CreateAdvertCommandHandler>(); services.AddTransient <ICommandHandler <UpdateAdvertCommand, Advert>, UpdateAdvertCommandHandler>(); services.AddTransient <ICommandHandler <PostAdvertCommand, Advert>, PostAdvertCommandHandler>(); services.AddTransient <ICommandHandler <PublishAdvertCommand, Advert>, PublishAdvertCommandHandler>(); services.AddTransient <ICommandHandler <WithdrawAdvertCommand, Advert>, WithdrawAdvertCommandHandler>(); services.AddTransient <ICommandHandler <StockUpdatedCommand, Advert>, StockUpdatedCommandHandler>(); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <Advert, AdvertDto>(); cfg.CreateMap <Advert, AddAdvertToStockDto>(); }); services.AddSingleton <AutoMapper.IMapper>(sp => config.CreateMapper()); services.AddSingleton <IEventStoreConnection>(sp => EventStoreConnection.Create(new Uri(_config["ApplicationSettings:EventStoreUrl"]))); services.AddScoped <ModelStateActionFilterAttribute>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <VODContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <User, IdentityRole>() .AddEntityFrameworkStores <VODContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddSingleton <IReadRepository, MockReadRepository>(); services.AddMvc(); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <Video, VideoDTO>(); cfg.CreateMap <Download, DownloadDTO>() .ForMember(dest => dest.DownloadUrl, src => src.MapFrom(s => s.Url)) .ForMember(dest => dest.DownloadTitle, src => src.MapFrom(s => s.Title)); cfg.CreateMap <Instructor, InstructorDTO>() .ForMember(dest => dest.InstructorName, src => src.MapFrom(s => s.Name)) .ForMember(dest => dest.InstructorDescription, src => src.MapFrom(s => s.Description)) .ForMember(dest => dest.InstructorAvatar, src => src.MapFrom(s => s.Thumbnail)); cfg.CreateMap <Course, CourseDTO>() .ForMember(dest => dest.CourseId, src => src.MapFrom(s => s.Id)) .ForMember(dest => dest.CourseTitle, src => src.MapFrom(s => s.Title)) .ForMember(dest => dest.CourseDescription, src => src.MapFrom(s => s.Description)) .ForMember(dest => dest.MarqueeImageUrl, src => src.MapFrom(s => s.MarqueeImageUrl)) .ForMember(dest => dest.CourseImageUrl, src => src.MapFrom(s => s.ImageUrl)); cfg.CreateMap <Module, ModuleDTO>() .ForMember(dest => dest.ModuleTitle, src => src.MapFrom(s => s.Title)); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var mappingConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.AddMapping(); }); services.AddSingleton(x => mappingConfig.CreateMapper()); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddScoped <ApplicationDbContext, ApplicationDbContext>(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddMvc(); services.AddDbContext <InventoryManagementWebContext>(options => options.UseSqlServer(Configuration.GetConnectionString("InventoryManagementWebContext"))); }
// This method gets called by the runtime. Use this method to add services to the container. /// <summary> /// Configures the services. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { string conn = Configuration.GetConnectionString("DefaultConnection").Replace("%CONTENTROOTPATH%", contentRootPath); services.AddTransient <IUserService, UserService>(); services.AddDbContext <DataContext>(options => options.UseSqlServer(conn)); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfileConfiguration()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddMvc(); services.AddControllersWithViews(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = nameof(AuthenticationApplication), Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddCaching(); services.AddMemoryCache(); services.AddSession(); services.AddMvc(); //Contection to database services.AddDbContext <ApplicationContext>(options => options.UseSqlServer(ApplicationContextFactory.Path)); //Repository Scopes services.AddScoped <IStageOfMethodRepository, StageOfMethodRepository>(); services.AddScoped <ITranslationOfWordRepository, TranslationOfWordRepository>(); services.AddScoped <IWordInEnglishRepository, WordInEnglishRepository>(); //Automapper var configAutomapper = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutomapperProfile()); }); var mapper = configAutomapper.CreateMapper(); services.AddSingleton(mapper); services.AddSingleton <ITempDataProvider, SessionStateTempDataProvider>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var autoMapperConfig = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile <Recruit.WebApi.Services.AutoMapperProfiles.AutoMapperProfile>());; autoMapperConfig.AssertConfigurationIsValid(); services.AddSingleton <AutoMapper.IMapper>(autoMapperConfig.CreateMapper()); Recruit.WebApi.Services.Bootstrap.Startup.Load(services); services.AddControllers(); services.AddSwaggerGen(c => { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); c.EnableAnnotations(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddCors(); var config = new AutoMapper.MapperConfiguration(c => { c.AddProfile(new ApplicationProfile()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddTransient <ICityRepository, EfCityRepository>(); services.AddTransient <ICountryRepository, EfCountryRepository>(); services.AddTransient <ICustomerRepository, EfCustomerRepository>(); services.AddTransient <ICustomerReservationRepository, EfCustomerReservationRepository>(); services.AddTransient <IDistrictRepository, EfDistrictRepository>(); services.AddTransient <IDocumentRepository, EfDocumentRepository>(); services.AddTransient <IHotelRepository, EfHotelRepository>(); services.AddTransient <IReservationRepository, EfReservationRepository>(); services.AddTransient <IRoomRepository, EfRoomRepository>(); services.AddTransient <IRoomTypeRepository, EfRoomTypeRepository>(); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddControllersWithViews(); services.AddDbContext <HotelServiceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var config = new AutoMapper.MapperConfiguration(c => { c.AddProfile(new AutoMapperProfiles()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); }
public HomeController(ILogger <HomeController> logger, Services.IDataService <KnowledgeBaseItem> dataService, Services.IQueryService <KnowledgeBaseItem> queryService) { _logger = logger; KnowledgeBaseData = dataService; KnowledgeBaseQuery = queryService; //TODO: Implement mapping from QuestionAndAnswerModel to Entities.KnowledgeBaseItem. //LastUpdateOn field is set with DateTime.Now and Tags field with lowercase. //Also create a map from TagItem to TagModel. //Use "mapper" attribute which is already defined. More information: https://docs.automapper.org/en/latest/Getting-started.html. var configurationManager = new AutoMapper.MapperConfiguration( cfg => { cfg.CreateMap <QuestionAndAnswerModel, KnowledgeBaseItem>() .ForMember(x => x.Query, opt => opt.MapFrom(z => z.Question)) .ForMember(x => x.LastUpdateOn, opt => opt.MapFrom(z => DateTime.Now)); cfg.CreateMap <TagItem, TagModel>(); }); mapper = configurationManager.CreateMapper(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // services.RegisterServices().RegisterDbConnection(() => Configuration["ConnectionStrings:KeyConnection"]); services.AddMvc(options => { options.Filters.Add(new ErrorHandlingFilter()); }); var config = new AutoMapper.MapperConfiguration(cfg => { }); services.AddControllers(); services.RegisterQueryProcessor(); services.RegisterCommandBus(); services.AddSwaggerGen(options => { options.SwaggerDoc("User", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "User APIs", Version = "v1", Description = "API Used in User domain." }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddCors(o => o.AddPolicy("UrlPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.Configure <MvcOptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("UrlPolicy")); }); var config = new AutoMapper.MapperConfiguration(mapperConfig => mapperConfig.AddProfile(new MappingProfile())); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddScoped <IAnswerRespository, AnswerRepository>(); services.AddScoped <IClassRepository, ClassRepository>(); services.AddScoped <ILectureRepository, LectureRepository>(); services.AddScoped <IQuestionAnswerRespository, QuestionAnswerRepository>(); services.AddScoped <IQuestionRepository, QuestionRepository>(); services.AddScoped <IStudentRepository, StudentRepository>(); services.AddScoped <ITeacherRepository, TeacherRepository>(); services.AddScoped <ITestRepository, TestRepository>(); services.AddScoped <ITeacherFacade, TeacherFacade>(); services.AddScoped <ITeacherLecturesRepository, TeacherLecturesRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <ITestFacade, TestFacade>(); services.AddScoped <ITestParametersRepository, TestParametersRepository>(); services.AddScoped <ITestResultsRepository, TestResultsRepository>(); }
Act IObsoleteAction.GetNewAction() { AutoMapper.MapperConfiguration mapConfigBrowserElementt = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <Act, ActBrowserElement>(); }); ActBrowserElement NewActBrowserElement = mapConfigBrowserElementt.CreateMapper().Map <Act, ActBrowserElement>(this); Type currentType = GetActionTypeByElementActionName(GenElementAction); if (currentType == typeof(ActBrowserElement)) { switch (GenElementAction) { case eHandleBrowseAlert.AcceptAlertBox: NewActBrowserElement.ControlAction = ActBrowserElement.eControlAction.AcceptMessageBox; break; case eHandleBrowseAlert.DismissAlertBox: NewActBrowserElement.ControlAction = ActBrowserElement.eControlAction.DismissMessageBox; break; case eHandleBrowseAlert.GetAlertBoxText: NewActBrowserElement.ControlAction = ActBrowserElement.eControlAction.GetMessageBoxText; break; case eHandleBrowseAlert.SendKeysAlertBox: NewActBrowserElement.ControlAction = ActBrowserElement.eControlAction.SetAlertBoxText; break; default: NewActBrowserElement.ControlAction = (ActBrowserElement.eControlAction)System.Enum.Parse(typeof(ActBrowserElement.eControlAction), GenElementAction.ToString()); break; } } if (currentType == typeof(ActBrowserElement)) { return(NewActBrowserElement); } return(null); }
public List <FooDto> RunAutomapper() { var configuration = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap <Foo, FooDto>(); }); // only during development, validate your mappings; remove it before release configuration.AssertConfigurationIsValid(); var mapper = configuration.CreateMapper(); var fooDtos = new List <FooDto>(); Foos.ForEach(foo => { fooDtos.Add(mapper.Map <FooDto>(foo)); }); return(fooDtos); }
/// <summary> /// 以地址/地標取得 google map 地理編碼資訊 /// </summary> /// <param name="parameter">地理位置參數Dto</param> /// <returns>GoogleGeoDataDto</returns> public GoogleGeoDataDto GetGeocoding(GeoLocationParameterDto parameter) { var result = new GoogleGeoDataDto(); var responseColletions = this.GisProxy.GetGeocoding(parameter); if (responseColletions.Status.Equals(GoogleLocateStatus.Success)) { var mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap<Infrastructure.ClassLibsProxy.Models.GoogleLocate, GoogleLocateDto>() .ForMember(d => d.County, o => o.MapFrom(s => s.City)) .ForMember(d => d.District, o => o.MapFrom(s => s.Area)) .ForMember(d => d.IsPrecise, o => o.MapFrom(s => s.PreciseLevel)); cfg.CreateMap<Infrastructure.ClassLibsProxy.Models.GoogleResponse, GoogleGeoDataDto>(); }); var mapper = mapConfig.CreateMapper(); result = mapper.Map<Infrastructure.ClassLibsProxy.Models.GoogleResponse, GoogleGeoDataDto>(responseColletions); } return result; }
public HttpResponseMessage Get([FromUri] SMEmployeeParameter parameter) { var validator = new SMEmployeeParameterValidator(); var validationResult = validator.Validate(parameter); if (!validationResult.IsValid) { var errorMessage = string.Join("\r\n", validationResult.Errors.Select(e => e.ErrorMessage)); throw new FluentValidation.ValidationException(errorMessage); } var mapConfig = new AutoMapper.MapperConfiguration(cfg => { cfg.CreateMap<SMEmployeeParameter, SMEmployeeParameterDto>(); cfg.CreateMap<SMEmployeeDeptDto, SMEmployeeDeptViewModel>(); cfg.CreateMap<SMEmployeeDto, SMEmployeeViewModel>(); }); var mapper = mapConfig.CreateMapper(); var parameterDto = mapper.Map<SMEmployeeParameter, SMEmployeeParameterDto>(parameter); var result = this.EmployeeService.Get(parameterDto); var response = mapper.Map<List<SMEmployeeDto>, List<SMEmployeeViewModel>>(result); return this.GenerateSuccessResponse(parameter, response); }