dependency injection - Implementing Repository without ORM or LINQ in 3 tier architecture -


i trying implement simple repository pattern ioc in current project. project 3 tier application ui layer (a web application), business logic layer (a class library) , data access layer (a class library). want use unity container microsoft enterprise library di. don't want use orm nhibernate, entity framework etc. don't want use linq sql. unfortunately not able find example of repository pattern implementation scenario. have decided go ahead , implement repository pattern based on understanding of concept.

in business layer have defined generic repository interface:

// namespace businesslayer interface irepository<t, u> {     //   add entity repository      void add(t entity);       //   single entity repository id     t getbyid(u id);      //   list of entities repository      // specified parameters     ienumerable<t> getlist(idictionary<string,u> parameters);     ...     ... } 

i use irepository interface in business service (which in business layer) data persistence operations:

// namespace businesslayer class businessservice {     irepository<businessobject, string> _myrepository;      //constructor injection     public businessservice(         irepository<businessobject,string> repository)     {         this._myrepository = repository;     }      public void add(businessobject obj)     {         _myrepository.add(obj);     }      public businessobject getbyid(string guid)     {         return _myrepository.getbyid(guid);     }     ....     .... }  public class businessobject {     public string businessproperty { get; set; } } 

the data access layer implements irepository. have reference of business layer library in data layer

using businesslayer;  // namespace dataaccesslayer public class businessobjectrepository<businessobject, string>      : irepository<businessobject, string> {      public void irepository<businessobject, string>.add(         businessobject entity)     {         //implement database insert here.     }       public businessobject irepository<businessobject, string>.getbyid(         string id)     {         //implement database fetch here.     }      ....     .... } 

finally in ui layer have references both, businesslayer , dataaccesslayer:

using businesslayer; using dataaccesslayer;  namespace uilayer {     void page_load(byval sender system.object,          byval e system.eventargs)     {         var businessobj = new businessservice(             new businessobjectrepository<businessobject, string>());     } } 

is how implement repository pattern ? can lead me on how can use unity block in above case di ?

as per rule of 3 tier, ui layer should not aware of data access layer. doing inversion of control data access layer business layer mean switching dependencies in reverse order. concrete instance of repository has supplied in ui layer. how 1 maintain rule of 3 tier when doing ioc ?


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -