문제

I have designed a multi-layer solution and created a bunch of Manager classes to implement Business Logic. All the managers are derived from BaseManager class. To be more clear, here's UserManager class:

public class UserManager : BaseManager
{
    public void Add(User user)
    {
       ...
    }
    public void Update(User user)
    {
       ...
    }
    public void Delete(User user)
    {
       ...
    }
    public bool GetAccessPermissions(User user)
    {
       ...
    }
}  

BaseManager is as follows:

public class BaseManager
{  
    protected IRepository repository = IoCLocator.Resolve<IRepository>();
    public BaseManager()
    {
        ...
    }
    // Some shared methods among manager classes.
}  

Now I skeptical that my manager classes should all be defined static, since they get their related entities on which they want to operate, as parameters. But As you see, I have some shared private/protected members which I should instantiate upon every call. (e.g. repository should be instantiated on each manager class's creation).

What are my choices to define managers classes as static and still have the protected members instantiated on each call to managers' methods?

올바른 솔루션이 없습니다

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