交友系统网站建设,三网合一网站报价,百度售后电话人工服务,建设一个网站要多少钱上永远的吗书接上文#xff1a;Abp 从空白WebApplication开始
开发环境#xff1a;.NET6、Volo.Abp
数据库#xff1a;Sqlite
说明#xff1a;纯属个人强行入门。我个人觉得按照官网的操作不舒服#xff0c;所以自己研究着来#xff0c;请读者根据自己的需要进行参考。我能保证的…书接上文Abp 从空白WebApplication开始
开发环境.NET6、Volo.Abp
数据库Sqlite
说明纯属个人强行入门。我个人觉得按照官网的操作不舒服所以自己研究着来请读者根据自己的需要进行参考。我能保证的是按照文章操作能够得到和我一样的结果。 1、项目搭建将项目分为以下几个层
1.1、用户接口层目前放了空白的WebApplication理论上不应该这样先这么放着吧。项目名称DemoAspNetCoreApplict少了几个字母哈哈。
1.2、应用层目前是空的
1.3、领域层创建库项目项目名称DemoDomain。
1.4、基础设施层创建库项目项目名称DemoEntityFrameworkCore。
2、创建领域层项目项目目录如下图 2.1、 项目中引入包情况如下
Project SdkMicrosoft.NET.SdkPropertyGroupTargetFrameworknet6.0/TargetFrameworkImplicitUsingsenable/ImplicitUsingsNullableenable/Nullable/PropertyGroupItemGroupPackageReference IncludeVolo.Abp.AspNetCore Version6.0.3 /PackageReference IncludeVolo.Abp.Ddd.Domain Version6.0.3 //ItemGroup/Project 2.2、创建文件夹Book在文件夹Book中添加类BookInfo.cs代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities.Auditing;namespace DemoDomain.Book
{public class BookInfo:FullAuditedAggregateRootGuid{public string Name { get; set; }public string Description { get; set; }}
}2.3、添加类DemoDomainAbpModule.cs代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;namespace DemoDomain
{[DependsOn(typeof(AbpDddDomainModule))]public class DemoDomainAbpModule:AbpModule{}
}3、创建基础设施层项目项目目录请看第一张图
3.1、项目中引入包情况如下 Project SdkMicrosoft.NET.SdkPropertyGroupTargetFrameworknet6.0/TargetFrameworkImplicitUsingsenable/ImplicitUsingsNullableenable/Nullable/PropertyGroupItemGroupPackageReference IncludeVolo.Abp.AspNetCore.Mvc Version6.0.3 /PackageReference IncludeVolo.Abp.EntityFrameworkCore Version6.0.3 /PackageReference IncludeVolo.Abp.EntityFrameworkCore.Sqlite Version6.0.3 //ItemGroupItemGroupProjectReference Include..\DemoDomain\DemoDomain.csproj //ItemGroup/Project
3.2、添加DemoEntityFrameworkCroeAbpModule.cs类代码如下
using DemoDomain;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.Modularity;namespace DemoEntityFrameworkCore
{[DependsOn(typeof(DemoDomainAbpModule),typeof(AbpEntityFrameworkCoreModule), typeof(AbpEntityFrameworkCoreSqliteModule))]public class DemoEntityFrameworkCroeAbpModule:AbpModule{public override void ConfigureServices(ServiceConfigurationContext context){base.ConfigureServices(context);ConfigureAbpDbContextOptions(opt {opt.UseSqlite();});var services context.Services;services.AddAbpDbContextDemoDbContext(options { options.AddDefaultRepositories(true);});}}
}3.3、添加DemoDbContext.cs类注意这里的BookInfom目前还未添加代码如下
using DemoDomain.Book;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;namespace DemoEntityFrameworkCore
{[ConnectionStringName(conn_mssql)]public class DemoDbContext : AbpDbContextDemoDbContext{public DbSetBookInfo BookInfos { get; set; }public DemoDbContext(DbContextOptionsDemoDbContext options) : base(options){}protected override void OnModelCreating(ModelBuilder modelBuilder){base.OnModelCreating(modelBuilder);}}
}3.4、以下内容是生成数据库时产生的不用理会 4、 创建用户接口层项目项目目录请看第一张图
4.1、项目中引入包情况如下
Project SdkMicrosoft.NET.Sdk.WebPropertyGroupTargetFrameworknet6.0/TargetFrameworkNullableenable/NullableImplicitUsingsenable/ImplicitUsings/PropertyGroupItemGroupPackageReference IncludeMicrosoft.EntityFrameworkCore.Tools Version6.0.26PrivateAssetsall/PrivateAssetsIncludeAssetsruntime; build; native; contentfiles; analyzers; buildtransitive/IncludeAssets/PackageReferencePackageReference IncludeVolo.Abp.AspNetCore.Mvc Version6.0.3 /PackageReference IncludeVolo.Abp.Autofac Version6.0.3 //ItemGroupItemGroupProjectReference Include..\DemoEntityFrameworkCore\DemoEntityFrameworkCore.csproj //ItemGroup/Project
4.2、添加类DemoAbpModule.cs代码如下
using Volo.Abp.Modularity;
using Volo.Abp.Autofac;
using Volo.Abp.AspNetCore;
using Volo.Abp;namespace DemoAspNetCoreApplict
{[DependsOn(typeof(AbpAspNetCoreModule),typeof(AbpAutofacModule))]public class DemoAbpModule:AbpModule{public override void OnApplicationInitialization(ApplicationInitializationContext context){//base.OnApplicationInitialization(context);var appcontext.GetApplicationBuilder();var envcontext.GetEnvironment();if(env.IsDevelopment()){app.UseExceptionHandler(/Error);app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles(); app.UseRouting();app.UseConfiguredEndpoints();}}
}4.3、修改Program.cs类代码如下
using DemoAspNetCoreApplict;
using DemoEntityFrameworkCore;
using Microsoft.EntityFrameworkCore;var builder WebApplication.CreateBuilder(args);
builder.Host.UseAutofac(); //Add this line
builder.Services.ReplaceConfiguration(builder.Configuration);
builder.Services.AddApplicationDemoAbpModule();
builder.Services.AddDbContextDemoDbContext(options
{options.UseSqlite(Data SourceE:\\ABP\\demo.db;);
});var app builder.Build();
app.InitializeApplication();
app.Run();
4.4、修改appsettings.json内容如下
{ConnectionStrings: {conn_mssql: Data SourceE:\\ABP\\demo.db;,Default: Data SourceE:\\ABP\\demo.db;},Logging: {LogLevel: {Default: Information,Microsoft: Warning,Microsoft.Hosting.Lifetime: Information}},AllowedHosts: *
}5、数据迁移操作
5.1、在E盘创建ABP文件夹在ABP文件夹中创建demo.db数据库。sqlite数据库如何创建可以参考这个连接SQLite创建数据库 -SQLite教程。
5.2、将DemoAspNetCoreApplict 设置为启动项目打开程序包管理器控制台默认项目选择DemoEntityFrameworkCore。
5.3、程序包管理器控制台中输入Add-Migration init。
5.4、程序包管理器控制台中输入Update-Database。 6、问题
6.1、大家可能注意到我的数据库连接字符串出现了很多次在DemoAspNetCoreApplict项目中的Program.cs类中有appsettings.json文件中有有效的是Program.cs类中的。具体什么情况我还不太明白有兴趣的大神请帮忙解答一下。
6.2、如果觉得一步步操作太累还可以直接下载我上传的资源链接如下
https://download.csdn.net/download/xingchengaiwei/88795248