最佳实践:如何正确地将合同公开给外部服务以与 MEF 一起使用?
基本上,我的 Client.exe 项目中有以下类:
Client.exe 项目:Foo.cs
public class Foo
{
[Import(typeof(IBarService))
private IBarService MyBarService { get; set; }
...
}
CoolBarService.dll 项目:CoolBarService.cs
[Export(typeof(IBarService))]
public class CoolBarService : IBarService
{
public int GetBar() { ... }
}
IBarService 去了哪里?目前,我将其放入自己的项目类库中,然后两个项目都引用该类库,但我不确定这是否是最佳实践。如果我只是将 IBarService 留在客户端应用程序中,CoolBarService 项目将无法编译,因为它不知道 IBarService 是什么(当然,除非我将相同的代码复制到其中)。
ServiceContracts.dll 项目:IBarService.cs
public interface IBarService
{
int GetBar();
}
Basically, I have the following class within my Client.exe project:
Client.exe Project: Foo.cs
public class Foo
{
[Import(typeof(IBarService))
private IBarService MyBarService { get; set; }
...
}
CoolBarService.dll Project: CoolBarService.cs
[Export(typeof(IBarService))]
public class CoolBarService : IBarService
{
public int GetBar() { ... }
}
Where does IBarService go? Currently, I'm throwing it into a project class library of its own, which is then referenced by both projects, but I'm not sure if this is the best-practice or not. If I simply leave the IBarService in the Client app, the CoolBarService project can not compile because it has no idea what a IBarService is (unless of course, I copy the same code into it).
ServiceContracts.dll Project: IBarService.cs
public interface IBarService
{
int GetBar();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,听起来您确实希望将合同放在单独的合同程序集中。
In this case it sounds like you do want to put your contracts in a separate contract assembly.