开发者

Constructor error in WCF service implemented with Repository and UnitofWork patterns

I have a WCF service which implemented using Repository and UnitofWork patterns. And now I am getting following error:

The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.

When I worked WIHTOUT these patterns it did not throw any error. HELP ?? SUGGESTIONS? How to get passed this error?

Following is the code snippet:

public class Service : IService
{

    private IUnitOfWork _unitOfWork;

    private IMyRepository _myRepository;

    // Dependency Injection enabled constructors

    public Service(IUnitO开发者_C百科fWork uow, IMyRepository myRepository)
    {
        _unitOfWork = uow;
        _myRepository = myRepository;
    }

}


If you use default service instancing you must provide parameterless constructor. Your design provides dependency injection through constructor. In such case you must have your own instance provider to call the constructor and create service instance. You can create per service instance provider, behavior and optionally service host but it is really bad way. The better way is to use Inversion of Control container which will resolve your dependencies from configuration. In that case you will have only one new instance provider, behavior and optionally service host.

Here you have very nice post about creating new instnace provider which resolve services through Unity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜