In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how the .NET Core uses the APB vNext framework. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Quick start case .NET Core console application 1. Installing the ABP framework core depends on Install-Package Volo.Abp.Core-Version 3.3.22. Create a startup module for ABP application
HelloAbpModule.cs
Using Volo.Abp.Modularity;namespace HelloAbp {/ startup module / public class HelloAbpModule: AbpModule {}} 3. Create a new service and register it in the startup module
HelloWorldService.cs
Using System;using Volo.Abp.DependencyInjection;namespace HelloAbp {/ TODO: ABP registration service method 1: inherit interface / ISingletonDependency, IScopedDependency, ITransientDependency / public class HelloWorldService: ITransientDependency {public void Run () {Console.WriteLine ($"{nameof (HelloAbpModule)}-{nameof (HelloWorldService)}: HelloWorld!");}} 4. Create the ABP application according to the startup module and call the service method registered in the application
Program.cs
Using System;using Microsoft.Extensions.DependencyInjection;using Volo.Abp;namespace HelloAbp {class Program {static void Main (string [] args) {/ / create abp application var application = AbpApplicationFactory.Create () according to startup module; / / initialize abp application application.Initialize () / / get the service var service registered in the application = application.ServiceProvider.GetService (); / / call the service method service.Run () in the application; Console.ReadKey ();} ASP.NET Core Web application 1. Installation of the ABP framework core depends on Install-Package Volo.Abp.Core-Version 3.3.2Install-Package Volo.Abp.AspNetCore.Mvc-Version 3.3.22. Create a startup module for ABP application
AppModule.cs
Using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.Hosting;using Volo.Abp;using Volo.Abp.AspNetCore.Mvc;using Volo.Abp.Modularity;namespace HelloWebAbp {/ startup module / TODO: 1. To configure the pipeline of the ASP.NET Core Web program in the startup module, you need to define the dependency on the ASP.NET CoreMvc module / [DependsOn (typeof (AbpAspNetCoreMvcModule))] public class AppModule: AbpModule {/ application initialization method / TODO: 2. Rewrite the initialization method of ABP application to build the middleware pipeline of ASP.NET Core application / public override void OnApplicationInitialization (ApplicationInitializationContext context) {/ / base.OnApplicationInitialization (context); var app = context.GetApplicationBuilder (); var env = context.GetEnvironment () If (env.IsDevelopment ()) {app.UseDeveloperExceptionPage ();} app.UseRouting (); / / TODO: 5. Modify the endpoint configuration of the program application to the endpoint configuration of the ABP application app.UseConfiguredEndpoints ();} 3. Register the ABP startup module and initialize the ABP application
Startup.cs
Using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace HelloWebAbp {/ program startup class / TODO: 3. In the Startup class, initialize the ABP application / public class Startup {/ / This method gets called by the runtime. Use this method to add services to the container. / / For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices (IServiceCollection services) {services.AddApplication ();} / This method gets called by the runtime. Use this method to configure the HTTP request pipeline. Public void Configure (IApplicationBuilder app, IWebHostEnvironment env) {app.InitializeApplication ();}}. Create a new controller to test the running status of the ABP application
HomeController.cs
Using Microsoft.AspNetCore.Mvc;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Volo.Abp.AspNetCore.Mvc;namespace HelloWebAbp.Controllers {/ controller / TODO: 4. Inherit the base class controller in the Abp framework (provides some convenient services and methods) / / public class HomeController: AbpController {public IActionResult Index () {return Content ("Hello world!");}} each case is broken
There can be many modules in ABP applications, but there can only be one startup module
There is no necessary connection between each module in the ABP application.
The services registered by each module in the ABP application are registered in the global container of the ABP application
Modules in ABP applications are also divided into two types: application module (business implementation) and framework module (technical implementation).
The top module in the ABP application is the startup module, and the last one to be loaded is the startup module.
Register a custom service in the module
HelloAbpModule.cs
Using System;using System.Collections.Generic;using System.Text;using Microsoft.Extensions.DependencyInjection;using Volo.Abp;using Volo.Abp.Modularity;namespace HelloAbp {/ startup module / public class HelloAbpModule: AbpModule {/ / TODO: rewrite the service configuration method of the ABP module and register the custom service public override void ConfigureServices (ServiceConfigurationContext context) {base.ConfigureServices (context) in the module. / / TODO: ABP registration service method 2: module registration context.Services.AddTransient ();}
Summary
Initialize the ABP module
1. Register ABP infrastructure and core services (module system related)
two。 Load all modules of the entire application, sorted by dependencies
3. Traverse all modules sequentially, executing the configuration method for each module
4. Traverse all modules sequentially, executing the initialization method for each module
Register a custom service using tag properties
HelloWorldService.cs
Using System;using System.Collections.Generic;using System.Text;using Microsoft.Extensions.DependencyInjection;using Volo.Abp.DependencyInjection Namespace HelloAbp {/ TODO: ABP registration service method 3: feature tag / ServiceLifetime.Singleton, ServiceLifetime.Scoped, ServiceLifetime.Transient / [Dependency (ServiceLifetime.Transient)] public class HelloWorldService {public void Run () {Console.WriteLine ($"{nameof (HelloAbpModule)}-{nameof (HelloWorldService)}: HelloWorld!") } use Autofac1. ABP in the project. Install Autofac module Install-Package Volo.Abp.Autofac-Version 3.3.22. Create a dependency on the Autofac module in the module
HelloAbpModule.cs
Using System;using System.Collections.Generic;using System.Text;using Microsoft.Extensions.DependencyInjection;using Volo.Abp;using Volo.Abp.Autofac;using Volo.Abp.Modularity Namespace HelloAbp {/ startup module / TODO: use the Autofac third-party dependency injection framework (which provides more advanced features) [DependsOn (typeof (AbpAutofacModule))] public class HelloAbpModule: AbpModule {public override void ConfigureServices (ServiceConfigurationContext context) {base.ConfigureServices (context); context.Services.AddTransient ();}} 3. Integrate Autofac when the ABP application is created
Program.cs
Using System;using Microsoft.Extensions.DependencyInjection;using Volo.Abp;namespace HelloAbp {class Program {static void Main (string [] args) {{/ / create abp application var application = AbpApplicationFactory.Create based on startup module (options = > {/ / integrated Autofac options.UseAutofac ()) }); / / initialize the abp application application.Initialize (); / / get the service var service = application.ServiceProvider.GetService () registered in the application; / / call the service method service.Run () in the application } Console.WriteLine ("Hello World!"); Console.ReadKey ();} thank you for reading! This is the end of the article on "how .NET Core uses the APB vNext Framework". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.