Tutorial by Examples

After the install of an IoC (Inversion of Control) container, some tweaks are needed to make it work. In this case, I'll use Ninject. In the NinjectWebCommon file, that is located in the App_Start folder, substitute the CreateKernel method with: private static IKernel CreateKernel() { ...
In the concrete class that need the service, use the interface to access the service instead of its implementation like: public class BenefitAppService { private readonly IBenefitService _service; public BenefitAppService(IBenefitService service) { _service = service; ...
The Constructor Dependency Injection requires parameters in the constructor to inject dependencies. So you have to pass the values when you create a new object. public class Example { private readonly ILogging _logging; public Example(ILogging logging) { this._logging = l...
public class Example { private FileLogging _logging; public Example() { this._logging = new FileLogging(); } }
public DateTime SomeCalculation() { return DateTime.Now.AddDays(3); } vs public DateTime SomeCalculation(DateTime inputDate) { return inputDate.AddDays(3); }
Dependency resolver is used to avoid tightly-coupled classes, improve flexibility and make testing easy. You can create your own dependency injector (not recomended) or use one of well-written and tested dependency injectors. In this example I am going to use Ninject. Step one: Create dependency re...

Page 1 of 1