ASP. NET zero--Infrastructure

Source: Internet
Author: User
Tags automap log4net

Basic FacilitiesStart class

ASP. NET core from startup in the application class initialization. We configure all libraries (including ABP) in this class. We recommend that you check this course first. It is also integrated into the OWIN. So, you can add Owin middleware here.

Bower and front-end dependencies

ASP. NET zero solution using Bower Package Manager to get front-end library dependencies (such as Bootstrap and jquery). Therefore, you can easily add new packages or update existing packages on the command line interface of Visual Studio or bower. You can See all installed Bower packages under the Dependencies/bower of the. Web.mvc Project.

application Services as an MVC API controller

the ASP. NET Zero project highly uses AJAX to provide a better user experience. the UI invokes the Application service method through Ajax . Therefore, you need to create an MVC API controller as an adapter (a client invokes the MVC API controller operation via AJAX and then invokes the application service method). The ABP framework automatically creates an MVC API controller for all application services. Therefore, you do not have to manually create an MVC API Controller for application services. For More information , see related documentation . When ABP dynamically creates a Web API controller, we can also create a regular MVC API controller as we have always done.

Localization of

The ASP. NET Zero user interface is fully localized. the AspNet Zero uses dynamic, database-based tenant localization (see the relevant section above).

The XML file is used as a basic translation of the desired language:

Phonebook will be your projectname. You can add more XML files by copying an XML file and converting it to the desired language. Please refer to the valid culture code .

When you add new localized text, add it to the default language of the XML file, and then use it in the application (in addition, add the converted value to the appropriate XML file). because the values in the XML file will be used by default, you do not need to add them to the database migration code.

The application language is defined in the defaultlanguagescreator class . This is used as the seed data in the Entity Framework Migration . Therefore, if you want to add a new default language , simply add it to the Defaultlanguagescreator class. In addition, you should add the corresponding XML file as described above as the default translation.

For more information, see localization and language Management documentation.

Entityframeworkcore Integration

The ASP. NET Zero template uses Entityframeworkcore code precedence and migration . Phonebook DbContext(Yourprojectdbcontext of your project) defines the DbContext class. The Migrations folder contains EF migrations.

Phonebook The Repositorybase class is the base class for your custom repository. For more information, see Entity Framework Integration documentation.

Database Migration

You can use the Package Manager console to add a new migration and update the database as you normally would. for more information, see the documentation for EF core .

Exception Handling

ASP. NET zero uses the exception handling system of the ABP . Therefore, you do not need to handle and care about exceptions most of the time.

The ASP. NET Zero Solution added exception handling middleware in the startup class :

If(env. Isdevelopment ()){    app. Usedeveloperexceptionpage (); }else{    app. Usestatuscodepageswithredirects ("?/Error? StatusCode = {0} ");     app. Useexceptionhandler ("/Error"); }

Therefore, you can get a well-formed exception page during development and create a more user-friendly error page in production. For more information, see Errorcontroller and its associated view (views\ Error).

User Password

ASP. NET core introduces user passwords system to store sensitive data in development. ASP. NET zero uses this system (it is configured correctly for your solution). You may want to use different connection strings (or social media API keys) in your development, and you do not want to add these secret data to the Appsettings.json in your project (and you do not want to submit these sensitive information to the source control system). This sensitive information is then stored on the local computer using the Secret Manager tool and allows the application to read them from the local computer, if available.

For example, you can use the following command at the location of the Windows command prompt in the core project to change the connection string for your local development environment:

Set Connectionstrings:default "Server = 1.2.3.4; Database = Myprojectdevdb; User = sa; Password = 12345678 "

This user password value overrides the value in Appsettings.json. For more information about user passwords , See ASP . NET 's own documentation .

Authorized Provider

the Authorization system is permission-based. Apppermissions A constant that contains a permission name, and the Appauthorizationprovider class defines all the permissions in the system. before using it in the application tier, we should define a permission.

See the licensing documentation to learn how to configure permissions.

Feature providers

The Appfeatureprovider class defines the functionality of a multi-tenant application. the feature name is defined as contants in the Appfeatures class .

See The Feature Management documentation to learn how to define and use features.

Set provider

each setting has a unique name. the setting name is defined as a constant in the AppSettings class . all settings and their default values are defined in the appsettingprovider class .

See setting up a document to learn how to create and use settings.

Navigation providers

Use The Appnavigationprovider class defines the automatically generated menu . We have two menus:main (the main menu of the back-end application) and FrontEnd(the main menu of the front-end Web site).

See the navigation documentation for more information.

Cache and Redis cache

ASP. NET zero uses a memory cache, but it can use Redis as the cache server. If you want to enable it, just uncomment the webcoremodule in the following line (in your. Web.core project):

Configuration.Caching.UseRedis (... );

The Redis server should be running to use it. For more information, see caching documents.

background jobs and Hangfire

The ABP Framework contains a background job system with default background Job management. If you want to use hangfire as background work management, you can easily enable it;

    1. Cancel Comment Addhangfire and usehangfiredashboard and usehangfireserver line in Startup.cs (of Web.mvc or Web.host Depending on your case).
    2. Uncomment Configuration.BackgroundJobs.UseHangfire in your. Web.core project in the WebCoreModule.cs class.

Note : hangfire will create its own tables in the database the first time it runs . For more information, see background work and hangfire intergation documentation.

SIGNALR Integration

the SIGNALR is correctly configured and integrated into the startup template. Real-time notifications and chat systems use it. You can use SIGNALR directly in your application.

attention; Currently, SignalR Not yet published to ASP. We integrate Owin into the ASP. NET core pipeline to use SIGNALR in the application. for More information on SignalR, see the SignalR integration documentation.

. Net Core Compatibility

Because SIGNALR is not ready for. NET core, if you choose. NET core as the underlying framework, the SIGNALR integration will be disabled.

Record

ASP. NET zero use Log4net as the default record. the configuration is defined in the. Web project's log4net.config file . it defaults to writing all the logs to the Web site's app_data/logs/logs.txt folder. When you publish your project, remember to configure Write access to the Logs folder .

Check the logging documentation to learn how to inject ILogger and write to the log.

DTO Mapping

ASP. NET zero use AutoMapper A DTO-to-entity mapping (and other types of object-to-object mappings). We use the Abp.automapper Library to make the use of automapper simpler and more declarative.

For example, see the DTO class for transferring tenant editing information:

[Automap (typeof(Tenant))]Publicclass  tenanteditdto:entitydto   {  [Required]   [Stringlength (tenant.maxtenancynamelength)]  public string  tenancyname { get ;     set;  }    [Required]   [Stringlength (tenant.maxnamelength)]  public string  Name { get ;  set  ;  }   public bool  IsActive { Span class= "Hljs-keyword" >get ; set    ;  }   }              /span>

here, Automap. properties automatically establish mappings Tenanteditdto and tenant classes. We can then automatically convert the tenant object to a Tenanteditdto object, as follows:

Public  Async taskgettenantforedit(entityrequestinput input){     Return(wait   tenantmanager.getbyidasync (input.id)). Mapto <TenantEditDto> (); }

The Mapto extension method performs the mapping.

Custom Object Mappings

In some cases, attribute-based mapping may be insufficient. If you need to configure the mappings directly using the AutoMapper API, you should do so in the Customdtomapper class.

for More information about DTOs, see data Transfer Object documentation .

send e-mail

in some cases, ASP. NET Zero sends an e-mail message to the user (such as a forgotten password and e-mail confirmation). e-mail templates are in . Core Project (default.html) in the emailing /emailtemplates folder definition . You can change the default e-mail template by editing this file.

e-Mail sending is disabled in debug mode. because the development environment may not be configured correctly to send e-mail messages. You can turn it on if you want. It is enabled in release mode. Check The Preinitialize method of the Yourprojectname Coremodule class if you are willing to change it.

. Net Core Compatibility

because. NET core does not support SMPT clients, AspNet Zero uses Mailkit send e-mail.

Binaryobjectmanager

The user profile picture is stored in the database, not the file system. However, because of performance reasons, it is not stored in the Users table (users often retrieve from the database, but rarely require a profile picture).

ASP. NET zero built-in universal binary save mechanism. The Binaryobject entity can be used to hold any type of binary object (a byte array). because the profile picture can be converted to a byte array, the user profile picture is saved here.

the Ibinaryobjectmanager interface defines methods for saving, acquiring, and deleting binary objects. Dbbinaryobjectmanager implements it to save binary objects in the database. For example,Profilecontroller uses Ibinaryobjectmanager to get the profile picture of the current user from the database.

You can create a different The Ibinaryobjectmanager interface is implemented to store files in another destination.

Soft Delete

The soft-delete mode is typically used to not delete an entity from the database, but only to mark it as deleted. Therefore, if an entity is soft-deleted, then it should not be accidentally retrieved into the application. the data filter for the ABP is automated .

in ASP. NET zero, most entities are soft-deleted. For more information about this topic , see the Data filter documentation for the ABP .

bundling, sorting and compiling

ASP. NET zero use Bundler&minifier Visual Studio Extensions to bundle and shrink scripts and style files. It should be installed in your Visual Studio. The Bundleconfig.json file defines all bundle configurations.

ASP. NET zero also uses the webcompiler Visual Studio Extension compiles less files into CSS files. This extension should also be installed in your Visual Studio. Compilerconfig.json defines all compilation configurations.

See the documentation for these extensions to learn how to use them.

Basic Class

Some useful base classes are used in the application:

    • phonebook  appservicebase can be used as the base class for all Apps program Services .
    • phonebook  domainservicebase can be used as a base class for Domain Services .
    • phonebook  controllerbase   can be used as an ASP. core  MVC Controller The base class for .
    • phonebook  razorpage   can act as asp.net  MVC view Base class for . in effect, all views are automatically inherited because it defines   in the _viewimports.cshtml file ; . You can add some common properties/methods here to use in all views.
    • phonebook  ServiceBase can be used as the base class for other similar services. For example, the Useremailer class inherits it.
    • phonebook  repositorybase can be used as   custom storage Base class   of the library implementation; .

It is strongly recommended that you inherit one of these classes as needed because they make logging, localization, authorization ... More easily.

CSRF/XSRF Protection

The ABP framework simplifies and automates csrf protection as much as possible. the AspNet Zero template is preconfigured and available out of the box. For more information, see the xsrf-csrf protection documentation for your ABP

version

The Appversionhelper class is used to define the current version of an application in a single location . the version and release date are automatically displayed in the lower-left corner of the back-end app page. This helps us always see the version of the application running.

ASP. NET zero--Infrastructure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.