Why would you do this?
This increases the grip in the application with the roof and can confuse your teammates to use the extension method (they need to keep in mind that each time this method is used, they enter the repository each time).
Instead, create a separate class and use the constructor injection to inject an instance of IRepository
:
public class StuffExecuter { private readonly IRepository _repository; public StuffExecuter(IRepository repository) { _repository = repository; } public bool CanExecute(BusinessObject obj) { _repository.Add(obj.UserName, new EArgument { Name = obj.Name }); } }
source share