Autofac TScanningActivatorData 和 WithMetadata
我正在尝试做这样的事情。然而 WithMetadata 方法不允许我这么做。
这是 Autofac 中的问题吗?是否应该将 WithMetadata 重载中的 TScanningActivatorData 更改为 TActivatorData,还是我以错误的方式处理此问题?
builder.RegisterType(myType).As<IMyType().AsSelf().WithMetadata("somekey", delegate(Type t)
{
//dosomething
return t;
});
这给了我 WithMetadata 方法上的错误: 类型 'Autofac.Builder.ConcreteReflectionActivatorData' 不能用作通用类型或方法 'Autofac.RegistrationExtensions.WithMetadata
I am trying to do something like this. However the WithMetadata method wont let me.
Is this a problem in Autofac and should TScanningActivatorData in the WithMetadata overloads be changed to TActivatorData, or am i approaching this the wrong way?
builder.RegisterType(myType).As<IMyType().AsSelf().WithMetadata("somekey", delegate(Type t)
{
//dosomething
return t;
});
This gives me the error on the WithMetadata method: The type 'Autofac.Builder.ConcreteReflectionActivatorData' cannot be used as type parameter 'TScanningActivatorData' in the generic type or method 'Autofac.RegistrationExtensions.WithMetadata<TLimit,TScanningActivatorData,TRegistrationStyle>(Autofac.Builder.IRegistrationBuilder<TLimit,TScanningActivatorData,TRegistrationStyle>, string, System.Func<System.Type,object>)'. There is no implicit reference conversion from 'Autofac.Builder.ConcreteReflectionActivatorData' to 'Autofac.Features.Scanning.ScanningActivatorData'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您想要实现的目标,有更合适的重载。传递给委托的
t
参数与myType
相同 - 因此等效代码是:您一直在查看的重载用于扫描注册,例如当使用
RegisterAssemblyTypes()
而不是RegisterType()
时。希望这有帮助。
缺口
There's a more suitable overload for what you're trying to achieve. The
t
parameter passed in to the delegate is the same asmyType
- so the equivalent code is:The overload you've been looking at is for use with scanning registrations, e.g. when using
RegisterAssemblyTypes()
rather thanRegisterType()
.Hope this helps.
Nick