IoC 和摘要 类
IoC and abstract classes
我正在编写一项服务,可以对 public 在各种情况下发表的评论进行情感分析。为此,我创建了以下界面:
项目 A:
public interface ISentimentEngine
{
SentimentEngineServices SentimentEngineProvider {get;}
ISentimentEngineResult AnalyseSentiment(ISentimentRequest request);
}
我还有一个摘要 class,它将包含我对实际服务的具体实现的一些通用功能:
项目 B:
public abstract class SentimentEngineBase
{
protected abstract int MaximumRequests { get; }
protected SentimentEngineBase(string configurationXml)
{
}
protected abstract SentimentEngineServices SentimentEngineProvider { get; }
protected abstract string SentimentEngineName { get; }
protected abstract void ProcessClientConfiguration(string configuration);
protected abstract void GetDefaultConfiguration();
}
以上抽象class与其他对象在同一个项目中,例如响应和请求实现以及接口都在单独的合同项目(A)中,在阶梯模式的实现中.
然后在进一步的项目中进行单独的实现:
项目 C:
public class MicrosoftAzureTextAnalyticsSentiment : SentimentEngineBase, ISentimentEngine
{
我不喜欢的一点是,服务的具体实现需要依赖基础抽象class(项目 B),以及接口(项目 A),同样如此我为每个服务提供商创建的所有实现,即 Microsoft Azure Text Analytics、Google Cloud Natural Language、Amazon Comprehend 等,它们都将在单独的项目中。
我想使用 IoC 并将接口注入各种对象构造函数:
选项是:
- 这一切都很好,没关系,别担心,继续前进!!!
- 将基础 class 分离到另一个项目,项目 D。将其与其他 classes 分离。
- 只使用接口,将一些抽象方法移到接口; (但我真的不喜欢他们拥有 public 属性并且不得不一直重新做腿部工作)。
- 是否有不同的方法。
抱歉,这对你们来说可能是基本的东西,我可能遗漏了一些明显的东西,但我看不到树木的木材。
谢谢,
斯图
我觉得还可以。是的,实现该接口的项目 C 将依赖于项目 A 和 B,Google Cloud Natural Language 的项目 C' 或 Amazon Comprehend 的 C" 也将依赖于项目 C。但是具有此 SentimentEngineConsumer
的不同项目 E
class SentimentEngineConsumer
{
ISentimentEngine _engine;
public SentimentEngineConsumer(ISentimentEngine engine)
{
_engine = engine;
}
...
}
只想用接口就不用项目B,C,C',C", ...直接用项目A就可以了,留给一个依赖注入模块就可以了 link C、C' 或 C" 到项目 E.
我正在编写一项服务,可以对 public 在各种情况下发表的评论进行情感分析。为此,我创建了以下界面:
项目 A:
public interface ISentimentEngine
{
SentimentEngineServices SentimentEngineProvider {get;}
ISentimentEngineResult AnalyseSentiment(ISentimentRequest request);
}
我还有一个摘要 class,它将包含我对实际服务的具体实现的一些通用功能:
项目 B:
public abstract class SentimentEngineBase
{
protected abstract int MaximumRequests { get; }
protected SentimentEngineBase(string configurationXml)
{
}
protected abstract SentimentEngineServices SentimentEngineProvider { get; }
protected abstract string SentimentEngineName { get; }
protected abstract void ProcessClientConfiguration(string configuration);
protected abstract void GetDefaultConfiguration();
}
以上抽象class与其他对象在同一个项目中,例如响应和请求实现以及接口都在单独的合同项目(A)中,在阶梯模式的实现中.
然后在进一步的项目中进行单独的实现:
项目 C:
public class MicrosoftAzureTextAnalyticsSentiment : SentimentEngineBase, ISentimentEngine
{
我不喜欢的一点是,服务的具体实现需要依赖基础抽象class(项目 B),以及接口(项目 A),同样如此我为每个服务提供商创建的所有实现,即 Microsoft Azure Text Analytics、Google Cloud Natural Language、Amazon Comprehend 等,它们都将在单独的项目中。
我想使用 IoC 并将接口注入各种对象构造函数:
选项是:
- 这一切都很好,没关系,别担心,继续前进!!!
- 将基础 class 分离到另一个项目,项目 D。将其与其他 classes 分离。
- 只使用接口,将一些抽象方法移到接口; (但我真的不喜欢他们拥有 public 属性并且不得不一直重新做腿部工作)。
- 是否有不同的方法。
抱歉,这对你们来说可能是基本的东西,我可能遗漏了一些明显的东西,但我看不到树木的木材。
谢谢,
斯图
我觉得还可以。是的,实现该接口的项目 C 将依赖于项目 A 和 B,Google Cloud Natural Language 的项目 C' 或 Amazon Comprehend 的 C" 也将依赖于项目 C。但是具有此 SentimentEngineConsumer
的不同项目 Eclass SentimentEngineConsumer
{
ISentimentEngine _engine;
public SentimentEngineConsumer(ISentimentEngine engine)
{
_engine = engine;
}
...
}
只想用接口就不用项目B,C,C',C", ...直接用项目A就可以了,留给一个依赖注入模块就可以了 link C、C' 或 C" 到项目 E.