neozhu / smartadmin.core.urf

Domain Driven Design (DDD) lightweight development architecture(support .net 5.0)
Apache License 2.0
110 stars 41 forks source link
asp-net-core ddd-architecture smartadmin web-application

Domain Driven Design (DDD) lightweight development architecture(support .net 5.0)

smartadmin.core.urf offers a complete, modular and layered software architecture based on Domain Driven Design principles and patterns. It also provides the necessary infrastructure to implement this architecture, focusing on the core of the business Demand, reduce duplication coding, allow junior programmers to develop professional and beautiful Web applications

Domain-driven design (DDD) is the concept that the structure and language of software code (class names, class methods, class variables) should match the business domain. For example, if a software processes loan applications, it might have classes such as LoanApplication and Customer, and methods such as AcceptOffer and Withdraw. DDD connects the implementation to an evolving model. Domain-driven design is predicated on the following goals:

  • placing the project's primary focus on the core domain and domain logic;
  • basing complex designs on a model of the domain;
  • initiating a creative collaboration between technical and domain experts to iteratively refine a conceptual model that addresses particular domain problems.。

    Demo Site

UserName:demo Password:123456 Demo (https://admin.i247365.net/)

Please give me Star if you like it. Every Star is a motivation to encourage me to continue updating.

Layers

smartadmin.core.urf follow the DDD design pattern to implement the four-layer model of the application

  • Presentation Layer:This layer is the part where interaction with external systems happens. This layer is the gateway to the effects that a human, an application or a message will have on the domain. Requests will be accepted from this layer and the response will be shaped in this layer and displayed to the user.the project use SmartAdmin - Responsive WebApp and Jquery EasyUI
  • Application Layer:It is the layer where business process flows are handled. The capabilities of the application can be observed in this layer. Domain entities are created and subject to update here. Depending on the usage scenarios, topics such as transaction management are also resolved here. In this layer, execution of work commands and reactions to domain events are coded. The code snippet for handling the CreateUser work command is given below as an example. In this example, by creating an object of User that comes from the Domain Layer and storing this object in the data storage, request for user creation is resolved. the project:StartAdmin.Service.csproj
  • Domain Layer:This will be the core of the application. It is the layer where all business rules related to the problem to be solved are included. In this layer; entities, value objects, aggregates, factories and interfaces will take place. This layer should be kept away from dependencies as much as possible. Third party libraries should not be added as much as possible, as it should not take other layers as a reference.the project use EntityFrmework Core Code-first and Repository Implement. the project:StartAdmin.Domain.csproj
  • Infrastructure Layer:This layer will be the layer that accesses external services such as database, messaging systems and email services. The IUserRepository interface designed in the domain layer and used in the application layer will be implemented in this layer and gain an identity.the project use:Nlog,service discovery:Swagger UI,EventBus:dotnetcore/CAP,Authentication and Authorization:Microsoft.AspNetCore.Identity,etc.

Project

get started

Start with the simple requirement \ develop CRUD, import and export function with Company object

<div id="customerdetailwindow" class="easyui-window" title="明细数据" data-options="modal:true, closed:true, minimizable:false, collapsible:false, maximized:false, iconCls:'fal fa-window', onBeforeClose:function(){ var that = $(this); if(customerhasmodified()){ $.messager.confirm('确认','你确定要放弃保存修改的记录?',function(r){ if (r){ var opts = that.panel('options'); var onBeforeClose = opts.onBeforeClose; opts.onBeforeClose = function(){}; that.panel('close'); opts.onBeforeClose = onBeforeClose; hook = false; } }); return false; } }, onOpen:function(){ $(this).window('vcenter'); $(this).window('hcenter'); }, onRestore:function(){ }, onMaximize:function(){ } " style="width:820px;height:420px;display:none">

@Html.AntiForgeryToken() @Html.HiddenFor(model => model.Id)

@await Component.InvokeAsync("ImportExcel", new ImportExcelOptions { entity = "Customer", folder = "Customers", url = "/Customers/ImportExcel", tpl = "/Customers/Download"

})

@section HeadBlock {

} @section ScriptsBlock {

}

> The code of the View layer above is very complicated, but they are all in a fixed format and can be quickly generated with scaffold
+ Configure dependency injection (DI), register services
> Open startup.cs 在 public void ConfigureServices(IServiceCollection services)
> register services 
services.AddScoped<IRepositoryX<Customer>, RepositoryX<Customer>>(); \
services.AddScoped<ICustomerService, CustomerService>();
+ migration database
> EF Core Code-First migration \
> in Visual Studio.Net \
> Package Manager Controle run \
>PM>:add-migration create_Company \
>PM>:update-database \
>PM>:migration
+ Debug project
![](https://raw.githubusercontent.com/neozhu/smartadmin.core.urf/master/img/meitu_1.jpg)

## 高级应用
> CAP The solution and application scenario of distributed transaction \
> nuget install \
>PM> Install-Package DotNetCore.CAP \
>PM> Install-Package DotNetCore.CAP.RabbitMQ \
>PM> Install-Package DotNetCore.CAP.SqlServer \
+ config Startup.cs
```javascript
public void ConfigureServices(IServiceCollection services)
    {
      services.AddCap(x =>
      {
        x.UseEntityFramework<SmartDbContext>();
        x.UseRabbitMQ("127.0.0.1");
        x.UseDashboard();
        x.FailedRetryCount = 5;
        x.FailedThresholdCallback = failed =>
        {
          var logger = failed.ServiceProvider.GetService<ILogger<Startup>>();
          logger.LogError($@"A message of type {failed.MessageType} failed after executing {x.FailedRetryCount} several times, 
                        requiring manual troubleshooting. Message name: {failed.Message.GetName()}");
        };
      });
    }

contact information

qq群!