Field-driven design practices-DDDLite-based permission management and dddlite permission management
Search for "permission management" in the garden to get at least thousands of valid records. I remember that writing a general permission system was always my dream at the beginning of my work. In the middle, the job is busy (in fact, it is just lazy !) And so on. Recently, when I write my own things, many of them are theoretical. I often cannot find a suitable example to illustrate my point of view. So I spent my spare time writing something.
The permission management system in garden has the following types:
Don't talk about anything. Do it! There are too many texts, so a dynamic graph can be slowed down:
Using OpenAuth. domain; using OpenAuth. domain. interface; using System. collections. generic; using System. linq; namespace OpenAuth. app {public class OrgManagerApp {private region _ repository; public OrgManagerApp (IOrgRepository repository) {_ repository = repository;} public IList <Org> GetAll () {return _ repository. loadOrgs (). toList () ;}//< summary> /// direct sub-department of the Department /// <para> TODO: Root Select LoadAllChildren or LoadDirectChildren </para> /// </summary> public IList <Org> LoadDirectChildren (int orgId) {return _ repository. find (u => u. parentId = orgId ). toList () ;}//< summary> /// obtain all sub-departments of the Department /// <para> If orgId is 0, obtain all departments </para> /// </summary> public IList <Org> LoadAllChildren (int orgId) {string cascadeId = "0. "; if (orgId! = 0) {var org = _ repository. findSingle (u => u. id = orgId); if (org = null) throw new Exception ("the specified object information cannot be found"); cascadeId = org. cascadeId;} return _ repository. find (u => u. cascadeId. contains (cascadeId) & u. id! = OrgId ). toList () ;}//< summary> /// Add a department /// </summary> public int AddOrUpdate (Org org) {if (org. id = 0) {ChangeModuleCascade (org); _ repository. add (org);} else {_ repository. update (org);} return org. id;} // <summary> // Delete the department with the specified ID and all its sub-departments. // </summary> public void DelOrg (int id) {var delOrg = _ repository. findSingle (u => u. id = id); if (delOrg = null) return; _ repository. delete (u => u. C AscadeId. contains (delOrg. cascadeId) ;}# region private method // modify the cascading ID of an object to generate a method similar to XXX. XXX. x. XX private void ChangeModuleCascade (Org org) {string cascadeId; int currentCascadeId = 1; // The Last var sameLevels = _ repository of the cascade node of the current node. find (o => o. parentId = org. parentId & o. id! = Org. id); foreach (var obj in sameLevels) {int objCascadeId = int. parse (obj. cascadeId. split ('. '). last (); if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;} if (org. parentId! = 0) {var parentOrg = _ repository. FindSingle (o => o. Id = org. ParentId); if (parentOrg! = Null) {cascadeId = parentOrg. cascadeId + ". "+ currentCascadeId; org. parentName = parentOrg. name;} else {throw new Exception ("unable to find the Organization's parent node information") ;}} else {cascadeId = "0. "+ currentCascadeId; org. parentName = "Root Node";} org. cascadeId = cascadeId;} # private endregion method }}
2. Textbook-level stratified thinking, even if you are reading a classic masterpiece of great gods (for example, enterprise application architecture model, reconstruction and model, ASP. NET Design Patterns, etc.), you can also refer to this project. Believe it? The project reference relationships automatically generated by Resharper are illustrated in the figure, without any trace of PS!
Https://git.oschina.net/yubaolee/OpenAuth.Net
The source code contains all program code, database PowerDesigner design drawing, CodeSmith generation template, and database initial script. Download the source code, use Nuget to restore the referenced third-party package, and then modify the connection string in web. config.
The current Code has implemented the following core functions:
- Hierarchical Management of modules, users, departments, and roles;
- Assign roles to users or directly assign modules to users;
- Adapt the module URL address to the Controller of MVC for authorization;
- Page menu button allocation;
- Log4net has been integrated internally. You only need a simple LogHelper. Log ("Log Content;
Features of recent development:
- Menu authorization process;
- Data permission processing;
- Hierarchical user authorization;
How can I complete the functions and ideas of a project in just one article! In subsequent blogs, I will share my thoughts on enterprise development, some opinions on DDD, some opinions on restructuring, and so on to describe my program life.
Other highlights of this blog: http://www.cnblogs.com/yubaolee/p/Catalogue.html