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

Split sekiban core into Sekiban.Core.Neutral and Sekiban.Core.AspNetCore #471

Merged
merged 10 commits into from
Dec 28, 2024
  •  
  •  
  •  
16 changes: 15 additions & 1 deletion Sekiban.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32328.378
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sekiban.Core", "src\Sekiban.Core\Sekiban.Core.csproj", "{55BD846C-C1F0-4187-A0D7-2013EEEFDBCE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sekiban.Core.Neutral", "src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj", "{55BD846C-C1F0-4187-A0D7-2013EEEFDBCE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{76D7B2DA-2E6B-4078-AC01-B29BCA83411A}"
EndProject
Expand Down Expand Up @@ -93,6 +93,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pure.Domain", "internalUsag
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pure.Domain.Test", "tests\Pure.Domain.Test\Pure.Domain.Test.csproj", "{51DF08A1-D72A-476E-80EC-77257CAD3132}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sekiban.Core", "src\Sekiban.Core\Sekiban.Core.csproj", "{524AE6A7-5B7C-4D22-B701-F926710BBBAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sekiban.Core.AspNetCore", "src\Sekiban.Core.AspNetCore\Sekiban.Core.AspNetCore.csproj", "{8DA8CCA4-3A14-4626-8883-207E80906911}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -263,6 +267,14 @@ Global
{51DF08A1-D72A-476E-80EC-77257CAD3132}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51DF08A1-D72A-476E-80EC-77257CAD3132}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51DF08A1-D72A-476E-80EC-77257CAD3132}.Release|Any CPU.Build.0 = Release|Any CPU
{524AE6A7-5B7C-4D22-B701-F926710BBBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{524AE6A7-5B7C-4D22-B701-F926710BBBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{524AE6A7-5B7C-4D22-B701-F926710BBBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{524AE6A7-5B7C-4D22-B701-F926710BBBAA}.Release|Any CPU.Build.0 = Release|Any CPU
{8DA8CCA4-3A14-4626-8883-207E80906911}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DA8CCA4-3A14-4626-8883-207E80906911}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DA8CCA4-3A14-4626-8883-207E80906911}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DA8CCA4-3A14-4626-8883-207E80906911}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -309,6 +321,8 @@ Global
{5D33366F-B87C-4B97-B5D5-03DE86FD1A8D} = {76D7B2DA-2E6B-4078-AC01-B29BCA83411A}
{59FE4616-6610-48AE-A44A-2AC2E1D27A05} = {B85F80AE-6A27-402C-93FA-352D938EDA8D}
{51DF08A1-D72A-476E-80EC-77257CAD3132} = {4C34F748-F223-44DD-899D-029F9CEF7780}
{524AE6A7-5B7C-4D22-B701-F926710BBBAA} = {76D7B2DA-2E6B-4078-AC01-B29BCA83411A}
{8DA8CCA4-3A14-4626-8883-207E80906911} = {76D7B2DA-2E6B-4078-AC01-B29BCA83411A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2DFBE53E-69A7-453A-8D20-72271AE32016}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<ProjectReference Include="..\SampleProject.Common\SampleProject.Common.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
</ItemGroup>


Expand Down
4 changes: 2 additions & 2 deletions internalUsages/FeatureCheck.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
}

app
.MapPost("/api/createbranchandclient", SekibanUsecase.CreateSimpleExecutorAsync<AddBranchAndClientUsecase, bool>())
.MapPost("/api/createbranchandclient", SekibanAspNetCoreUsecase.CreateSimpleExecutorAsync<AddBranchAndClientUsecase, bool>())
.WithName("CreateBranchAndClientU")
.WithOpenApi();

app
.MapPost("/api/createbranch", CommandExecutor.CreateSimpleCommandExecutor<CreateBranch>())
.MapPost("/api/createbranch", AspNetCoreCommandExecutor.CreateSimpleCommandExecutor<CreateBranch>())
.WithName("CreateBranchU")
.WithOpenApi();

Expand Down
2 changes: 1 addition & 1 deletion internalUsages/Mixed.Domain/Mixed.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
<ProjectReference Include="..\Shipping.Domain\Shipping.Domain.csproj"/>
<ProjectReference Include="..\Warehouse.Domain\Warehouse.Domain.csproj"/>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion internalUsages/Shipping.Domain/Shipping.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
<ProjectReference Include="..\Shipping.Port\Shipping.Port.csproj"/>
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion internalUsages/Warehouse.Domain/Warehouse.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/>
<ProjectReference Include="..\..\src\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
<ProjectReference Include="..\Shipping.Port\Shipping.Port.csproj"/>
<ProjectReference Include="..\Warehouse.Port\Warehouse.Port.csproj"/>
</ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions src/Sekiban.Core.AspNetCore/Command/AspNetCoreCommandExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sekiban.Core.Usecase;

namespace Sekiban.Core.Command;

public class AspNetCoreCommandExecutor
{
public static Func<TCommon, ISekibanExecutor, Task<IResult>> CreateSimpleCommandExecutor<TCommon>()
where TCommon : class, ICommandCommon =>
([FromBody] input, [FromServices] executor) => executor.ExecuteCommand(input).ToResults();

public static Func<TCommon, ISekibanExecutor, Task<IResult>> CreateSimpleCommandExecutorWithErrorHandler<TCommon>(
Func<Exception, IResult> errorHandler) where TCommon : class, ICommandCommon =>
([FromBody] input, [FromServices] executor) => executor.ExecuteCommand(input).ToResults();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Http;
using System.Security.Claims;

namespace Sekiban.Core.Command.UserInformation;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Http;
using System.Security.Claims;

namespace Sekiban.Core.Command.UserInformation;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Sekiban.Core.Command.UserInformation;

namespace Sekiban.Core.Dependency;

/// <summary>
/// Extension methods for <see cref="IServiceCollection" />
/// </summary>
public static class SekibanAspNetCoreServiceExtensions
{
public enum HttpContextType
{
Local = 1, Azure = 2
}

public static IServiceCollection AddSekibanHTTPUser(
this IServiceCollection services,
HttpContextType contextType = HttpContextType.Local)
{
// Users Information
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
switch (contextType)
{
case HttpContextType.Local:
services.AddTransient<IUserInformationFactory, HttpContextUserInformationFactory>();
break;

case HttpContextType.Azure:
services.AddTransient<IUserInformationFactory, AzureAdUserInformationFactory>();
break;
}

return services;
}
}
41 changes: 41 additions & 0 deletions src/Sekiban.Core.AspNetCore/Sekiban.Core.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<PackageId>Sekiban.Core.AspNetCore</PackageId>
<Version>0.22.1</Version>
<Authors>J-Tech Group</Authors>
<Company>J-Tech-Japan</Company>
<PackageDescription>Sekiban - Event Sourcing Framework AspNetCore Extensions</PackageDescription>
<RepositoryUrl>https://github.com/J-Tech-Japan/Sekiban</RepositoryUrl>
<PackageVersion>0.22.1</PackageVersion>
<Description>Initial .NET 9 Release</Description>
<AssemblyName>Sekiban.Core.AspNetCore</AssemblyName>
<RootNamespace>Sekiban.Core</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<GenerateSBOM>true</GenerateSBOM>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Sbom.Targets" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Sekiban.Core.Neutral\Sekiban.Core.Neutral.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ResultBoxes;

namespace Sekiban.Core.Usecase;

public static class SekibanUsecase
public static class SekibanAspNetCoreUsecase
{
public static IResult ToResults<TResult>(this ResultBox<TResult> resultBox) where TResult : notnull =>
Results.Ok(resultBox.UnwrapBox());

public static async Task<IResult> ToResults<TResult>(this Task<ResultBox<TResult>> resultBox)
where TResult : notnull => Results.Ok(await resultBox.UnwrapBox());



public static Func<TUsecase, ISekibanExecutor, Task<IResult>> CreateSimpleExecutorAsync<TUsecase, TOut>()
where TUsecase : class, ISekibanUsecaseAsync<TUsecase, TOut>, IEquatable<TUsecase> where TOut : notnull =>
([FromBody] input, [FromServices] executor) => executor.ExecuteUsecase(input).ToResults();



public static Func<TUsecase, ISekibanExecutor, IResult> CreateSimpleExecutor<TUsecase, TOut>()
where TUsecase : class, ISekibanUsecase<TUsecase, TOut>, IEquatable<TUsecase> where TOut : notnull =>
([FromBody] input, [FromServices] executor) => executor.ExecuteUsecase(input).ToResults();




public static Func<TIn, ISekibanExecutor, IResult> CreateExecutor<TIn, TOut>(
ISekibanUsecase<TIn, TOut> usecase,
Func<Exception, IResult> exceptionMatch) where TIn : class, ISekibanUsecase<TIn, TOut>, IEquatable<TIn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ResultBoxes;
using Sekiban.Core.Aggregate;
using Sekiban.Core.Command.UserInformation;
Expand All @@ -13,7 +11,6 @@
using Sekiban.Core.Snapshot.Aggregate;
using Sekiban.Core.Snapshot.Aggregate.Commands;
using Sekiban.Core.Types;
using Sekiban.Core.Usecase;
using Sekiban.Core.Validation;
using System.Collections.Immutable;
namespace Sekiban.Core.Command;
Expand Down Expand Up @@ -561,12 +558,4 @@ private async Task<List<IEvent>> HandleEventsAsync<TAggregatePayload, TCommand>(
await eventWriter.SaveAndPublishEvents(events, new AggregateWriteStream(typeof(TAggregatePayload)));
return toReturnEvents;
}


public static Func<TCommon, ISekibanExecutor, Task<IResult>> CreateSimpleCommandExecutor<TCommon>()
where TCommon : class, ICommandCommon =>
([FromBody] input, [FromServices] executor) => executor.ExecuteCommand(input).ToResults();
public static Func<TCommon, ISekibanExecutor, Task<IResult>> CreateSimpleCommandExecutorWithErrorHandler<TCommon>(
Func<Exception, IResult> errorHandler) where TCommon : class, ICommandCommon =>
([FromBody] input, [FromServices] executor) => executor.ExecuteCommand(input).ToResults();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MemStat.Net;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Sekiban.Core.Cache;
using Sekiban.Core.Command;
Expand All @@ -24,11 +23,6 @@ namespace Sekiban.Core.Dependency;
/// </summary>
public static class SekibanCoreServiceExtensions
{
public enum HttpContextType
{
Local = 1, Azure = 2
}

public enum MultiProjectionType
{
Simple = 1, MemoryCache = 2
Expand Down Expand Up @@ -240,22 +234,12 @@ var snapshotTakingBackgroundService
return services;
}

public static IServiceCollection AddSekibanHTTPUser(
public static IServiceCollection AddSekibanConstantUser(
this IServiceCollection services,
HttpContextType contextType = HttpContextType.Local)
string userInfo = "Const User Information")
{
// Users Information
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
switch (contextType)
{
case HttpContextType.Local:
services.AddTransient<IUserInformationFactory, HttpContextUserInformationFactory>();
break;
case HttpContextType.Azure:
services.AddTransient<IUserInformationFactory, AzureAdUserInformationFactory>();
break;
}

var factory = new ConstUserInformationFactory(userInfo);
services.AddSingleton<IUserInformationFactory>(factory);
return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sekiban.Core.Command;
using Sekiban.Core.Setting;
using Sekiban.Core.Shared;
Expand All @@ -22,8 +22,8 @@ public static class SekibanEventSourcingDependency
/// <param name="builder"></param>
/// <param name="dependencyDefinition"></param>
/// <returns></returns>
public static WebApplicationBuilder AddSekibanWithDependency(
this WebApplicationBuilder builder,
public static IHostApplicationBuilder AddSekibanWithDependency(
this IHostApplicationBuilder builder,
IDependencyDefinition dependencyDefinition)
{
builder.Services.AddSekibanWithDependency(dependencyDefinition, builder.Configuration);
Expand All @@ -35,7 +35,7 @@ public static WebApplicationBuilder AddSekibanWithDependency(
/// <param name="builder"></param>
/// <typeparam name="TDependency"></typeparam>
/// <returns></returns>
public static WebApplicationBuilder AddSekibanWithDependency<TDependency>(this WebApplicationBuilder builder)
public static IHostApplicationBuilder AddSekibanWithDependency<TDependency>(this IHostApplicationBuilder builder)
where TDependency : IDependencyDefinition, new()
{
builder.Services.AddSekibanWithDependency(new TDependency(), builder.Configuration);
Expand All @@ -49,8 +49,8 @@ public static WebApplicationBuilder AddSekibanWithDependency<TDependency>(this W
/// <param name="dependencyDefinition"></param>
/// <param name="settings"></param>
/// <returns></returns>
public static WebApplicationBuilder AddSekibanWithDependency(
this WebApplicationBuilder builder,
public static IHostApplicationBuilder AddSekibanWithDependency(
this IHostApplicationBuilder builder,
IDependencyDefinition dependencyDefinition,
SekibanSettings settings)
{
Expand Down Expand Up @@ -162,7 +162,7 @@ SekibanCoreServiceExtensions.MultiProjectionType multiProjectionType
GetAssembly()));
// Sekiban Event Sourcing
services.AddSekibanCore(settings, sekibanDateProducer ?? new SekibanDateProducer(), multiProjectionType);
services.AddSekibanHTTPUser();
services.AddSekibanConstantUser();
services.AddSingleton(settings);
services.AddTransient<IAggregateSettings, ContextAggregateSettings>();
// run Define() before using.
Expand Down Expand Up @@ -217,7 +217,7 @@ public static void RegisterForInMemoryTest(
// Sekiban Event Sourcing
services.AddSekibanCoreInMemory(sekibanDateProducer);

services.AddSekibanHTTPUser();
services.AddSekibanConstantUser();
services.AddSingleton(SekibanSettings.Default);
services.AddTransient<IAggregateSettings, ContextAggregateSettings>();
// run Define() before using.
Expand Down Expand Up @@ -273,7 +273,7 @@ public static void RegisterForAggregateTest(
// Sekiban Event Sourcing
services.AddSekibanCoreAggregateTest(sekibanDateProducer);

services.AddSekibanHTTPUser();
services.AddSekibanConstantUser();
services.AddSingleton(SekibanSettings.Default);
services.AddSekibanAppSettingsFromObject(new AggregateSettings());
// run Define() before using.
Expand Down
Loading
Loading