gpt4 book ai didi

c# - 实现多个接口(interface)的类如何使用RegisterType?

转载 作者:太空宇宙 更新时间:2023-11-03 20:19:40 25 4
gpt4 key购买 nike

给定:

public interface IFeedOperations : IOperationsWithPreInstalledData
{
...
}

public class FeedOperations : IFeedOperations
{
}

如何为实现 IFeedOperations 的类使用 RegisterType因此 IOperationsWithPreInstalledData还有吗?

public class FeedsInstaller : IDependencyInstaller
{
public void Install(IDependencyContainer container)
{
container.RegisterType(typeof(IFeedOperations), typeof(FeedOperations));
container.RegisterType(typeof(IOperationsWithPreInstalledData), typeof(FeedOperations));
}
}

当前代码产生以下错误。如果我删除第二个 RegisterType,那么我在调用 container.ResolveAll<IOperationsWithPreInstalledData>() 时不会得到任何结果。 .

Component ...Feeds.FeedOperations could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.

如果我删除第二个 RegisterType,那么我在调用 container.ResolveAll<IOperationsWithPreInstalledData>() 时不会得到任何结果。 .温莎城堡似乎没有看到实现 IFeedOperations 的类还实现了 IOperationsWithPreInstalledData .

我如何向 CaSTLe Windsor 注册我的实现类,以便它知道我的类实现了两个接口(interface)——或者更确切地说,我的类可以解析任一接口(interface)。

最佳答案

container.Register(Component.For<IFoo,IBar>().ImplementedBy<FooBar>());

关于c# - 实现多个接口(interface)的类如何使用RegisterType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14428572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com