如何在类库项目中配置自动映射器? [英] How to configure Auto mapper in class library project?
本文介绍了如何在类库项目中配置自动映射器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是第一次使用自动映射.
I am using auto mapping first time.
我正在使用c#应用程序,并且想使用自动映射器.
I am working on c# application and I want to use auto mapper.
(我只是想知道如何使用它,所以我既没有asp.net应用程序,也没有MVC应用程序.)
(I just want to know how to use it, so I don't have asp.net app neither MVC app.)
我有三个班级图书馆项目.
I have three class library projects.
我想在服务项目中编写传输过程.
I want to write transfer process in the service project.
所以我想知道如何以及在哪里配置自动映射器?
So I want to know how and where should I configure the Auto Mapper ?
推荐答案
您可以将配置放在任何地方:
You can place the configuration anywhere:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(x =>
{
x.AddProfile<MyMappings>();
});
}
}
public class MyMappings : Profile
{
public override string ProfileName
{
get { return "MyMappings"; }
}
protected override void Configure()
{
......
}
但是它必须由应用程序在某些时候使用库来调用:
But it has to be called by the application using the libraries at some point:
void Application_Start()
{
AutoMapperConfiguration.Configure();
}
这篇关于如何在类库项目中配置自动映射器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文