我有WCF服务,就像ORM一样。我需要一个映射器将实体映射到Dtos。考虑到关注点的分离(、SOLID和DDD ),我想知道AutoMapper配置和概要文件应该去哪里?我的项目结构看起来是这样的:
数据(EF) -> Logic -> WCF Services / WCF Contracts -> WindowsService (主机)
我遵循了github的规则,创建了一个尼尼微模块:
public class AutoMapperModule : NinjectModule
{
public override void Load()
{
Bind<IValueResolver<SourceEntity, DestModel, bool>>().To<MyResolver>();
var mapperConfiguration = CreateConfiguration();
Bind<MapperConfiguration>().ToConstant(mapperConfiguration).InSingletonScope();
// This teaches Ninject how to create automapper instances say if for instance
// MyResolver has a constructor with a parameter that needs to be injected
Bind<IMapper>().ToMethod(ctx =>
new Mapper(mapperConfiguration, type => ctx.Kernel.Get(type)));
}
private MapperConfiguration CreateConfiguration()
{
var config = new MapperConfiguration(cfg =>
{
cfg.AddProfiles(new SampleProfile());
});
return config;
}
}
public class SampleProfile : Profile
{
public SomeProfile()
{
CreateMap<Foo, FooDto>();
}
}我总是在可执行程序的入口创建一个Ninject模块,所以在Windows中是这样的。但是我有点困惑,因为我的Windows项目没有“数据”引用(与实体)。所以我有几个问题:
谢谢!
发布于 2018-03-06 07:30:33
使用Java,使用此结构
数据(EF) -> Logic -> WCF Services / WCF Contracts -> WindowsService (主机)
我认为是一套不同的包/项目。因此,每个包/项目(按我的解释)如下:
WindowsService (主机)是一种基础结构层,所有的东西都放在一起。在这里,您需要引用要使用的每个包/项目(数据、逻辑、WCF服务/ WCF合同)。
发布于 2018-03-06 15:39:40
将配置文件放在逻辑中,因为这是您可以将其放在最上游的点,即逻辑有映射的两面(实体和Dtos)。如果您想像@Luca建议的那样保持逻辑的美观整洁,那么您可能会考虑将Dtos移动到WCF层(以及Profiles)。
您的windows服务肯定已经有了对此逻辑的引用。
这样,其他项目,一个可能使用这个逻辑的web应用程序也可以使用这个配置文件。
https://stackoverflow.com/questions/49124143
复制相似问题