Question

I have a typical repository that implements the respective interface :

public class AccountRepository : IAccountRepository, IDisposable
{
....

Meanwhile inside this repository I am using a static helper class. What's the correct approach to static classes ? Since they cannot implement interfaces?

I want my repository to be decoupled (DI pattern), but I don't know how to apply it to static classes that my repository use.

Thanks

Was it helpful?

Solution

Why do you have an issue with the static classes in your repository class. A repository class is generally used to decouple your data access code from the rest of your application. This essentially allows you to replace your data access provider without to much effort by re-implementing your concrete repository classes for a new data access provider.

You can use DI to inject your repository class into either your controller or a service class.

If you really want to get your head around DI I would recommend reading "Dependency Injection in .Net" by Mark Seeman.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top