Browse Source

Merge pull request #10839 from abpframework/auto-merge/rel-5-0/679

Merge branch dev with rel-5.0
pull/10849/head
maliming 4 years ago
committed by GitHub
parent
commit
ee23e33cb3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 103
      docs/en/Getting-Started-AspNetCore-Application.md
  2. BIN
      docs/en/images/create-aspnet-core-application.png

103
docs/en/Getting-Started-AspNetCore-Application.md

@ -1,10 +1,10 @@
# Getting Started ABP With AspNet Core MVC Web Application # Getting Started With an ABP and AspNet Core MVC Web Application
This tutorial explains how to start ABP from scratch with minimal dependencies. You generally want to start with the **[startup template](Getting-Started-AspNetCore-MVC-Template.md)**. This tutorial explains how to start ABP from scratch with minimal dependencies. You generally want to start with the **[startup template](Getting-Started-AspNetCore-MVC-Template.md)**.
## Create A New Project ## Create a New Project
1. Create a new AspNet Core Web Application from Visual Studio 2019 (16.8.0+): 1. Create a new AspNet Core Web Application with Visual Studio 2022 (17.0.0+):
![](images/create-new-aspnet-core-application-v2.png) ![](images/create-new-aspnet-core-application-v2.png)
@ -12,19 +12,19 @@ This tutorial explains how to start ABP from scratch with minimal dependencies.
![](images/select-empty-web-application-v2.png) ![](images/select-empty-web-application-v2.png)
3. Press to the create button: 3. Press the create button:
![create-aspnet-core-application](images/create-aspnet-core-application.png) ![create-aspnet-core-application](images/create-aspnet-core-application.png)
## Install Volo.Abp.AspNetCore.Mvc Package ## Install Volo.Abp.AspNetCore.Mvc Package
Volo.Abp.AspNetCore.Mvc is AspNet Core MVC integration package for ABP. So, install it to your project: Volo.Abp.AspNetCore.Mvc is the AspNet Core MVC integration package for ABP. So, install it on your project:
```` ````
Install-Package Volo.Abp.AspNetCore.Mvc Install-Package Volo.Abp.AspNetCore.Mvc -Version 5.0.0-rc.1
```` ````
## Create First ABP Module ## Create the First ABP Module
ABP is a modular framework and it requires a **startup (root) module** class derived from ``AbpModule``: ABP is a modular framework and it requires a **startup (root) module** class derived from ``AbpModule``:
@ -40,21 +40,20 @@ namespace BasicAspNetCoreApplication
[DependsOn(typeof(AbpAspNetCoreMvcModule))] [DependsOn(typeof(AbpAspNetCoreMvcModule))]
public class AppModule : AbpModule public class AppModule : AbpModule
{ {
public override void OnApplicationInitialization( public override void OnApplicationInitialization(ApplicationInitializationContext context)
ApplicationInitializationContext context)
{ {
var app = context.GetApplicationBuilder(); var app = context.GetApplicationBuilder();
var env = context.GetEnvironment(); var env = context.GetEnvironment();
// Configure the HTTP request pipeline.
if (env.IsDevelopment()) if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{ {
app.UseExceptionHandler("/Error"); app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
} }
app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
@ -65,38 +64,33 @@ namespace BasicAspNetCoreApplication
``AppModule`` is a good name for the startup module for an application. ``AppModule`` is a good name for the startup module for an application.
ABP packages define module classes and a module can depend on another. In the code above, the ``AppModule`` depends on the ``AbpAspNetCoreMvcModule`` (defined by [Volo.Abp.AspNetCore.Mvc](https://www.nuget.org/packages/Volo.Abp.AspNetCore.Mvc) package). It's common to add a ``DependsOn`` attribute after installing a new ABP nuget package. ABP packages define module classes and a module can depend on another. In the code above, the ``AppModule`` depends on the ``AbpAspNetCoreMvcModule`` (defined by the [Volo.Abp.AspNetCore.Mvc](https://www.nuget.org/packages/Volo.Abp.AspNetCore.Mvc) package). It's common to add a ``DependsOn`` attribute after installing a new ABP NuGet package.
Instead of the Startup class, we are configuring ASP.NET Core pipeline in this module class. Instead of the Startup class, we are configuring an ASP.NET Core pipeline in this module class.
## The Startup Class ## The Program Class
Next step is to modify Startup class to integrate to ABP module system: Next step is to modify the Program class to integrate to the ABP module system:
````C# ````C#
using Microsoft.AspNetCore.Builder; using BasicAspNetCoreApplication;
using Microsoft.Extensions.DependencyInjection;
namespace BasicAspNetCoreApplication var builder = WebApplication.CreateBuilder(args);
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<AppModule>();
}
public void Configure(IApplicationBuilder app) builder.Services.ReplaceConfiguration(builder.Configuration);
{
app.InitializeApplication(); builder.Services.AddApplication<AppModule>();
}
} var app = builder.Build();
}
app.InitializeApplication();
app.Run();
```` ````
``services.AddApplication<AppModule>()`` adds all services defined in all modules starting from the ``AppModule``. ``builder.Services.AddApplication<AppModule>();`` adds all services defined in all modules starting from the ``AppModule``.
``app.InitializeApplication()`` in ``Configure`` method initializes and starts the application. ``app.InitializeApplication()`` initializes and starts the application.
## Run the Application! ## Run the Application!
@ -111,10 +105,10 @@ Replacing AspNet Core's DI system by Autofac and integrating to ABP is pretty ea
1. Install [Volo.Abp.Autofac](https://www.nuget.org/packages/Volo.Abp.Autofac) package 1. Install [Volo.Abp.Autofac](https://www.nuget.org/packages/Volo.Abp.Autofac) package
```` ````
Install-Package Volo.Abp.Autofac Install-Package Volo.Abp.Autofac -Version 5.0.0-rc.1
```` ````
2. Add ``AbpAutofacModule`` Dependency 2. Add the ``AbpAutofacModule`` Dependency
````C# ````C#
[DependsOn(typeof(AbpAspNetCoreMvcModule))] [DependsOn(typeof(AbpAspNetCoreMvcModule))]
@ -127,28 +121,23 @@ public class AppModule : AbpModule
3. Update `Program.cs` to use Autofac: 3. Update `Program.cs` to use Autofac:
````csharp ````C#
using Microsoft.AspNetCore.Hosting; using BasicAspNetCoreApplication;
using Microsoft.Extensions.Hosting;
namespace BasicAspNetCoreApplication var builder = WebApplication.CreateBuilder(args);
{
public class Program builder.Host.UseAutofac(); //Add this line
{
public static void Main(string[] args) builder.Services.ReplaceConfiguration(builder.Configuration);
{
CreateHostBuilder(args).Build().Run(); builder.Services.AddApplication<AppModule>();
}
var app = builder.Build();
app.InitializeApplication();
app.Run();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseAutofac(); //Add this line
}
}
```` ````
## Source Code ## Source Code

BIN
docs/en/images/create-aspnet-core-application.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Loading…
Cancel
Save