Open noufionline opened 8 years ago
@noufionline Thanks for the suggestion. Can you provide a sample implementation? Feel free to fork the repo, create a branch, and submit a pull request. Sounds like a good idea.
Sure! But the only change required must be a single interface which will provide a Generic Method Retrieve/Create desired Repository.
public interface IRepositoryFactory
{
T GetRepository<T>();
}
and this interface must be injected in your Unit Of Work class
public NorthwindUnitOfWork(INorthwindSlimContext context,
IRepositoryFactory repositoryRepository) :
base(context as DbContext)
{
_repositoryRepository = repositoryRepository;
}
The implementation of this interface should be left to users who might prefer to create the repository using reflection or a prefred container, or may be a default implementation can be provided with a concrete base class which can be overriden by the user.
in my case I prefer to use my container to resolve the requested repository.
By doing this only the required repository will be created and can avoid unncessery creation of all the repositories even when only one or two is used.
If you can do this in your T4 Template then all the repository can be created using this factory.
@noufionline Thanks, I'll have a look at putting the interface into the Patterns lib. Not sure if I currently have the bandwidth to update the UoW template, but I can look into that.
I noticed you opened a PR #148 -- is there a reason why you closed it?
I am creating a pull request for the first time and was confused a lil bit. Now I have two pull requests don't know how to delete my own code.
But it's a good beginning anyways :)
What you want to do is to a) fork the TE repo, b) create a local branch, c) commit your changes to the local branch you created, d) publish your branch, e) create a new pull request. Hope that helps.
Thanks a lot for your tips. :) It really helped.
Created a pull request #149 to address this issue.
Hi Tony,
First of all, Kudos for your excellent contribution to the community.
Wouldn't it be nice if we introduce RepositoryFactory Pattern and Inject only that in the UnitOfWork Constructor.
So instead of this
Something like this
in this way we can avoid injecting all the repositories from the constructor.