This blogpost has a sample-solution attached. Feel free to look into it. But before you do let me explain this package a bit. It will use the UnitOfWork, you will be able to use GenericRepositories and Customrepositories and everything is cached so that if you use the repositories in one using they only have to be created once.
I wont go into details about the sense of the UnitOfWork-thing but I want to give you code-examples how you can start with this in just a few minutes of your time.
If you want to work with the UnitOfWork in this NuGet-Package you will have two different possibilities:
Use generic repositories
Extend the generic repositories to use your own functions additional to the given CRUD-operations
I want to handle both cases in this post:
First of all you have to install the NuGet-Package. It will add you the needed dll you can work with.
1) Use generic repositories
The common case is that you have a DatabaseContext and DbSets of you entities stored in it. After adding the package you can use the OsUnitOfWorkContext as follows
2) Use extended repositories
If you want the normal repository to extend a bit with your own functions this is also possible. Everything you have to do is writing your own repository. You can even overwrite the normal CRUD-Methods to do whateer you like in there.
Attention to inherit it from the “IRepositoryContext" respectively the "RepositoryContextImpl". The code should look like this:
You can then use it with
With this you can build your own repositories and they are build up modular and are replacable in an easy way.
Thats it. I think this is nice and smooth. I hope you can get along with it. Have fun.