-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib-automapper.cs
More file actions
executable file
·25 lines (21 loc) · 919 Bytes
/
lib-automapper.cs
File metadata and controls
executable file
·25 lines (21 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Projekt.csproj
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
// WebApplicationBuilder (builder.Services)
Services.AddAutoMapper(x => x.AddMaps(typeof(IWorkshopperApi)));
// - nebo když je potřeba inject více services z DI
Services.AddSingleton(sp => new MapperConfiguration(cfg =>
{
cfg.AddProfile<RegistrationProfile>();
cfg.AddProfile(new WebinarProfile(sp.CreateScope().ServiceProvider.GetRequiredService<FilePaths>()));
}).CreateMapper());
// MappingProfile.cs
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<Registration, RegistrationModel>()
.ForMember(dest => dest.Name, src => src.MapFrom(x => x.FirstName + " " + x.LastName))
.ForMember(dest => dest.EventName, src => src.MapFrom(x => x.Event.Title));
CreateMap<RegistrationModelCreate, Registration>();
}
}