문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top