简体   繁体   中英

Repository: Examples for a Decorator / Repository pattern in C#

I had the wrong idea of how to create a repository. I created a single repository for each Entity that would CRUD using an ORM, which worked very well. However, I needed more and didn't know how to do it without messing up my existing code.

I wanted to add filtering based on Logins. I eventually found Castle.Windsor references showing something like this:

var ControllerContactRepo = new SecurityContactRepo( new ContactRepo() );

Where the Controller in MVC accesses one repository for Contacts which handles both CRUD and security without the controller knowing it. I presume the POCOs passed between repositories change based on the Liskov substitution principle, and the repositories are done with the decorator design pattern?

Where can I see some C# examples of this technique before I jump head first in to Castle Windsor? I am familiar with Constructor based IoC but not so much DI. I really want to know the nuts and bolts of this technique before I abstract it away with Windsor.

Links to website tutorials would be great, or book suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM