Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: play with .NET aspire #48

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions VerticalSliceArchitectureTemplate.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{21C89A08
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VerticalSliceArchitectureTemplate.Unit.Tests", "tests\VerticalSliceArchitectureTemplate.Unit.Tests\VerticalSliceArchitectureTemplate.Unit.Tests.csproj", "{07A76FBE-083C-49AA-856E-0C1B95DEB7B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VerticalSliceArchitectureTemplate.AppHost", "src\VerticalSliceArchitectureTemplate.AppHost\VerticalSliceArchitectureTemplate.AppHost.csproj", "{4749B813-0C0B-4596-9008-9369B4CD027C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,9 +32,14 @@ Global
{07A76FBE-083C-49AA-856E-0C1B95DEB7B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07A76FBE-083C-49AA-856E-0C1B95DEB7B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07A76FBE-083C-49AA-856E-0C1B95DEB7B2}.Release|Any CPU.Build.0 = Release|Any CPU
{4749B813-0C0B-4596-9008-9369B4CD027C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4749B813-0C0B-4596-9008-9369B4CD027C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4749B813-0C0B-4596-9008-9369B4CD027C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4749B813-0C0B-4596-9008-9369B4CD027C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8EB413BD-C5DF-49A5-A372-4AEAF4999952} = {92C5999C-A447-479E-8630-064E6FDC78DA}
{07A76FBE-083C-49AA-856E-0C1B95DEB7B2} = {21C89A08-D942-45BE-A302-4EEB543573C0}
{4749B813-0C0B-4596-9008-9369B4CD027C} = {92C5999C-A447-479E-8630-064E6FDC78DA}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions src/VerticalSliceArchitectureTemplate.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var builder = DistributedApplication.CreateBuilder(args);

var appDb = builder
.AddSqlServer("db")
.AddDatabase("appdb");

builder.AddProject<Projects.VerticalSliceArchitectureTemplate>("webapi")
.WithReference(appDb);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15230",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16214"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="8.0.0-preview.4.24156.9" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VerticalSliceArchitectureTemplate\VerticalSliceArchitectureTemplate.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ public static class DependencyInjection
public static void AddEfCore(this IServiceCollection services)
{
services.AddScoped<ISaveChangesInterceptor, EventPublisher>();

services.AddDbContext<AppDbContext>((sp, options) =>
{
options.UseInMemoryDatabase("InMemoryDbForTesting");

options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
});

services.AddSqlServerDbContext<AppDbContext>("appdb");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VerticalSliceArchitectureTemplate.Common.Persistence.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Todos",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Text = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
IsCompleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Todos", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Todos");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using VerticalSliceArchitectureTemplate.Common.Persistence;

#nullable disable

namespace VerticalSliceArchitectureTemplate.Common.Persistence.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("VerticalSliceArchitectureTemplate.Features.Todos.Models.Todo", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");

b.Property<bool>("IsCompleted")
.HasColumnType("bit");

b.Property<string>("Text")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("nvarchar(1024)");

b.HasKey("Id");

b.ToTable("Todos");
});
#pragma warning restore 612, 618
}
}
}
9 changes: 9 additions & 0 deletions src/VerticalSliceArchitectureTemplate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
using var scope = app.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();

await dbContext.Database.EnsureCreatedAsync();
await dbContext.Database.MigrateAsync();
}

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.4.24156.9" />
<PackageReference Include="MediatR" Version="12.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
</ItemGroup>

Expand Down
Loading