开发者

Best Practice: How do you properly expose your contract to an external service for use with MEF?

开发者 https://www.devze.com 2023-02-15 03:48 出处:网络
Basically, I have the following class within my Client.exe project: Client.exe Project: Foo.cs public class Foo

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

publ开发者_JAVA技巧ic interface IBarService
{
    int GetBar();
}


In this case it sounds like you do want to put your contracts in a separate contract assembly.

0

精彩评论

暂无评论...
验证码 换一张
取 消