design patterns - Interface of Interface using C# -
I do not know the following is weird but really needs an interface for an interface & lt; T & gt;
Example:
Public Interface IRAPSorporation & lt; T & gt; To store it in a list without specifying a specific implementation. {Add Zero (T-NNTTY); Remove zero (T unit); IEnumerable & LT; T & gt; find all(); IEnumerable & LT; T & gt; Search (Expression & lt; Funk & lt; T, bool & gt; & gt; Forecasting); } Public Interface IUnitOfWork {// Here I would like to store only one irapository without the implementation of ILIST & lt; IRepository & lt; ** I have to specify the implementation here ** & gt; & Gt; Repositories {receive; Set; } Bool Commit (); } You can recommend me better ways to do this. This is only what I have to do ...
Thanks Edit I Can not provide a non-normal interface because I'm using it like this:
Public class generic repository & lt; T & gt; : IRAPSorgetry & Lt; T & gt; {... general repository methods ...} // special repositories ... public class MyTableClassRepository & lt; MyTable & gt; : Generic Repository & lt; MyTable & gt; {Public MyTableClassRepository (database reference): base (context) {}}
consider The following design
Public Interface IUnitOfWork: IDisposable {T GetRepository & lt; T & gt; () Where T: Class; Zero attendance (); } In the implementation of the unitoffer you can use the IoC container (Autofac in the example below)
public class UnitOfWork: IUnitOfWork {Private static IContainer _container; Hashtable _repositories = new hashtable (); Get the Public Static Module CurrentRepositoriesModule { Set; } Public Universe () {var Builder = New Containerbuilder (); If (CurrentRepositoriesModule! = Zero) Builder Registrar Module (CurrentRepositoriesModule); _ Container = Builder. Build (); } Public T GetRepository & lt; T & gt; () Where T: class {var targetType = typeof (T); If (! _positories.kantensky (target type)) {_repositories.Add (target type, _ container.resolive & lt; T & gt; ()); } Return (t) _ repositories [targetType]; } Public Zero Save Changes () {New Notificied Exposition (throw); }}
Comments
Post a Comment