【发布时间】:2020-08-13 11:59:52
【问题描述】:
class Person : IParticipant {}
class Doctor: Person {}
class RandomParticipantGenerator : IParticipantGenerator{
enum PersonType
{
Person,
Doctor
}
public IParticipant GetParticipant(PersonType type, State state)
{
}
public List<IParticipant> GetParticipants(PersonType type, State state, int numOfPeople)
{
}
}
我的程序中有这些类,我需要能够使用GetParticipant 方法生成Person/Doctor。它应该返回一个Docter 当PersonType 枚举是Doctor 一个新的Person 当提供的类型等于Person。
我正在使用一个简单的工厂方法,但我想使用 Autofac 来实现它。
我很想在这件事上得到一些帮助。
【问题讨论】:
-
你能分享一下你到目前为止的尝试吗?
-
直到现在我还没有使用 autofac。如果类型是人,我只是返回新人。现在我希望发生的是 autofac 根据类型为我提供选择的实现,我不知道该怎么做。
标签: c# .net-core dependency-injection autofac factory