Automapper 自定义解析器 - 将存储库注入构造函数

Pau*_*ett 5 c# dependency-injection castle-windsor inversion-of-control automapper

我正在尝试为 automapper 创建一个自定义解析器,它需要访问我的数据存储库之一以检索登录的用户帐户。

到目前为止,这是我的代码...

public class FollowingResolver : ValueResolver<Audio, bool>
    {
        readonly IIdentityTasks identityTasks;

        public FollowingResolver(IIdentityTasks identitTasks)
        {
            this.identityTasks = identitTasks;
        }

        protected override bool ResolveCore(Audio source)
        {
            var user = identityTasks.GetCurrentIdentity();
            if (user != null)
                return user.IsFollowingUser(source.DJAccount);

            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是我收到此错误:

FollowingResolver' does not have a default constructor
Run Code Online (Sandbox Code Playgroud)

我曾尝试添加默认构造函数,但那时我的存储库从未被初始化。

这是我的自动放大器初始化代码:

public static void Configure(IWindsorContainer container)
        {
            Mapper.Reset();
            Mapper.Initialize(x =>
            {
                x.AddProfile<AccountProfile>();
                x.AddProfile<AudioProfile>();
                x.ConstructServicesUsing(container.Resolve);
            });

            Mapper.AssertConfigurationIsValid();
        }
Run Code Online (Sandbox Code Playgroud)

我错过了什么,甚至有可能这样做还是我错过了这里的船?

Pau*_*ett 4

不久之后找到了解决方案...我忘记将解析器添加为 IoC 容器。

现在效果很好!