What should web.config look like in Injection Dependency Injection for WCF services?

I am creating a new instnace provider that enables services through Unity. I am not sure how to add the configuration to web.config. Below is my class of service.

public class Service: IService {

private IUnitOfWork _unitOfWork; 

private IMyRepository _myRepository; 

// Dependency Injection enabled constructors 

public Service(IUnitOfWork uow, IMyRepository myRepository) 
{ 
    _unitOfWork = uow; 
    _myRepository = myRepository; 
} 

public bool DoWork()
{
        return true;
}

}

+3
source share
1 answer

You should use only web.config if you need to change services after compilation . This should not be considered a default scenario.

This means that in most cases it would be better to resort to Code as Configuration , for example:

container.RegisterType<Service>();
container.RegisterType<IUnitOfWork, MyUnitOfWork>();
container.RegisterType<IMyRepository, MyRepository>();

XML, - . Unity .

, :

<container>
  <register type="Service" />
  <register type="IUnitOfWork" mapTo="MyUnitOfWork" />
  <register type="IMyRepository" mapTo="MyRepository" />
</container>
+3

Source: https://habr.com/ru/post/1765913/


All Articles