2

私はしばらく AutoMapper を使用しています。次のようなプロファイル設定があります。

public class ViewModelAutoMapperConfiguration : Profile
    {
        protected override string ProfileName
        {
            get { return "ViewModel"; }
        }

        protected override void Configure()
        {
            AddFormatter<HtmlEncoderFormatter>();
            CreateMap<IUser, UserViewModel>();

        }
    }

次の呼び出しを使用して、これをマッパーに追加します。

Mapper.Initialize(x => x.AddProfile<ViewModelAutoMapperConfiguration>());

ViewModelAutoMapperConfigurationただし、 IoC を使用して依存関係をコンストラクターに渡したいと考えています。オートファクを使用しています。ここの記事を読んでいます:http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/05/11/automapper-and-ioc.aspxしかし、これがプロファイルでどのように機能するかわかりません.

何か案は?ありがとう

4

2 に答える 2

1

のオーバーロードを使用してそれを行う方法を見つけましたAddProfile。プロファイルのインスタンスを受け取るオーバーロードがあるため、メソッドに渡す前にインスタンスを解決できますAddProfile

于 2010-03-08T19:02:32.013 に答える