开发者

Can Wcf service contract also be used by others(nhibernate asp.net)

I was wondering about if wcf would be kinda break down if mixed in with IRepository

because 2 different sources are going to be using the same contract: - 1 being used by WCF - another by Asp.net Nhibernate

So i wanted to reuse the same contract rather making another replica with one or 2 things out.

Easier understood by an example...

[ServiceContract]
public interface ITutorialService
{
    [OperationContract]
    void AddTutorial(Tutorial newTutorial);
    [OperationContract]
    List<Tutorial> GetTutorials();
    [OperationContract]
    void RemoveTutorial(string id);

    Tutorial GetTutorialModel();
    Tag GetTagModel();
    Video GetVideoModel();

    IRepository<Tutorial> GetTutorialRepository();
    IRepository<Tag> GetTagRepository();
    IRepository<Video> GetVideoRepository();
}

[ServiceBehavior(Instance开发者_如何转开发ContextMode = InstanceContextMode.Single)]
public class TutorialService : ITutorialService
{
    private IRepository<Tutorial> _tutorial;
    private IRepository<Tag> _tag;
    private IRepository<Video> _video;......

in short would the wcf work fine as i didnt add any [OperationContract] to the Irepository ?


Yes it will work. The methods without [OperationContract] won't be WCF operations, but it sounds like that's what you want.

Another approach would be to have two interfaces and have one derive from the other so that you have separation of concerns, but do not have to define the methods twice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜