Implemented test app with the ABP Framework.

pull/6762/head
Halil İbrahim Kalkan 5 years ago
parent 333540e5e8
commit 085cf3e6c0

@ -5,9 +5,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="4.0.2" />
<PackageReference Include="Volo.Abp.Autofac" Version="4.0.2" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="4.0.2" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="4.0.2"/>
<PackageReference Include="Volo.Abp.Autofac" Version="4.0.2"/>
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="4.0.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -1,8 +1,11 @@
using Microsoft.AspNetCore.Builder;
using AbpPerfTest.WithAbp.EntityFramework;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Modularity;
@ -15,6 +18,19 @@ namespace AbpPerfTest.WithAbp
)]
public class AppModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookDbContext>(options =>
{
options.AddDefaultRepositories();
});
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AbpPerfTest.WithAbp.Dtos;
using AbpPerfTest.WithAbp.Entities;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
namespace AbpPerfTest.WithAbp.Controllers
{
[Route("api/books")]
public class BookController : Controller
{
private readonly IRepository<Book, Guid> _bookRepository;
public BookController(IRepository<Book, Guid> bookRepository)
{
_bookRepository = bookRepository;
}
[HttpGet]
public async Task<List<BookDto>> GetListAsync()
{
var books = await _bookRepository.GetListAsync();
return books
.Select(b => new BookDto
{
Id = b.Id,
Name = b.Name,
Price = b.Price,
IsAvailable = b.IsAvailable
})
.ToList();
}
[HttpGet]
[Route("{id}")]
public async Task<BookDto> GetAsync(Guid id)
{
var book = await _bookRepository.GetAsync(id);
return new BookDto
{
Id = book.Id,
Name = book.Name,
Price = book.Price,
IsAvailable = book.IsAvailable
};
}
[HttpPost]
public async Task<Guid> CreateAsync(CreateUpdateBookDto input)
{
var book = new Book
{
Name = input.Name,
Price = input.Price,
IsAvailable = input.IsAvailable
};
await _bookRepository.InsertAsync(book);
return book.Id;
}
[HttpPut]
[Route("{id}")]
public async Task UpdateAsync(Guid id, CreateUpdateBookDto input)
{
var book = await _bookRepository.GetAsync(id);
book.Name = input.Name;
book.Price = input.Price;
book.IsAvailable = input.IsAvailable;
}
[HttpDelete]
[Route("{id}")]
public async Task DeleteAsync(Guid id)
{
await _bookRepository.DeleteAsync(id);
}
}
}

@ -0,0 +1,15 @@
using System;
namespace AbpPerfTest.WithAbp.Dtos
{
public class BookDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public float Price { get; set; }
public bool IsAvailable { get; set; }
}
}

@ -0,0 +1,11 @@
namespace AbpPerfTest.WithAbp.Dtos
{
public class CreateUpdateBookDto
{
public string Name { get; set; }
public float Price { get; set; }
public bool IsAvailable { get; set; }
}
}

@ -0,0 +1,19 @@
using System;
using Volo.Abp.Domain.Entities;
namespace AbpPerfTest.WithAbp.Entities
{
public class Book : BasicAggregateRoot<Guid>
{
public string Name { get; set; }
public float Price { get; set; }
public bool IsAvailable { get; set; }
public Book()
{
Id = Guid.NewGuid();
}
}
}

@ -0,0 +1,28 @@
using AbpPerfTest.WithAbp.Entities;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace AbpPerfTest.WithAbp.EntityFramework
{
public class BookDbContext : AbpDbContext<BookDbContext>
{
public DbSet<Book> Books { get; set; }
public BookDbContext(DbContextOptions<BookDbContext> builderOptions)
: base(builderOptions)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Book>(b =>
{
b.ToTable("Books");
b.Property(x => x.Name).HasMaxLength(128);
});
}
}
}

@ -0,0 +1,29 @@
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace AbpPerfTest.WithAbp.EntityFramework
{
public class BookDbContextFactory : IDesignTimeDbContextFactory<BookDbContext>
{
public BookDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<BookDbContext>()
.UseSqlServer(configuration.GetConnectionString("Default"));
return new BookDbContext(builder.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false);
return builder.Build();
}
}
}

@ -0,0 +1,48 @@
// <auto-generated />
using System;
using AbpPerfTest.WithAbp.EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
namespace AbpPerfTest.WithAbp.Migrations
{
[DbContext(typeof(BookDbContext))]
[Migration("20201222135738_Added_Books")]
partial class Added_Books
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.UseIdentityColumns()
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.1");
modelBuilder.Entity("AbpPerfTest.WithAbp.Entities.Book", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsAvailable")
.HasColumnType("bit");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<float>("Price")
.HasColumnType("real");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,31 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace AbpPerfTest.WithAbp.Migrations
{
public partial class Added_Books : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
Price = table.Column<float>(type: "real", nullable: false),
IsAvailable = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Books");
}
}
}

@ -0,0 +1,46 @@
// <auto-generated />
using System;
using AbpPerfTest.WithAbp.EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
namespace AbpPerfTest.WithAbp.Migrations
{
[DbContext(typeof(BookDbContext))]
partial class BookDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.UseIdentityColumns()
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.1");
modelBuilder.Entity("AbpPerfTest.WithAbp.Entities.Book", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsAvailable")
.HasColumnType("bit");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<float>("Price")
.HasColumnType("real");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

@ -6,5 +6,8 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=AbpPerfTest_WithAbp;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

@ -5,11 +5,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1"/>
</ItemGroup>
</Project>

@ -56,7 +56,6 @@ namespace AbpPerfTest.WithoutAbp.Controllers
{
var book = new Book
{
Id = Guid.NewGuid(),
Name = input.Name,
Price = input.Price,
IsAvailable = input.IsAvailable

@ -11,5 +11,10 @@ namespace AbpPerfTest.WithoutAbp.Entities
public float Price { get; set; }
public bool IsAvailable { get; set; }
public Book()
{
Id = Guid.NewGuid();
}
}
}

Loading…
Cancel
Save