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)
我错过了什么,甚至有可能这样做还是我错过了这里的船?
归档时间: |
|
查看次数: |
6927 次 |
最近记录: |