Skip to content

Commit 2cec280

Browse files
committed
Added InMemory & EFCore NuGet-Aimed Projects
1 parent 2a16cad commit 2cec280

File tree

32 files changed

+331
-120
lines changed

32 files changed

+331
-120
lines changed

UltimateAuth.slnx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<Solution>
2+
<Folder Name="/Packages/">
3+
<Project Path="nuget/CodeBeam.UltimateAuth.EntityFrameworkCore/CodeBeam.UltimateAuth.EntityFrameworkCore.csproj" Id="764569b4-dd5b-4a18-a332-7307d20ee21a" />
4+
<Project Path="nuget/CodeBeam.UltimateAuth.InMemory/CodeBeam.UltimateAuth.InMemory.csproj" />
5+
</Folder>
26
<Folder Name="/Samples/">
37
<Project Path="samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/CodeBeam.UltimateAuth.Sample.BlazorServer.csproj" />
48
<Project Path="samples/blazor-standalone-wasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm.csproj" Id="27bd3c4d-65a9-4c70-a6c9-4178b1897730" />
@@ -15,9 +19,7 @@
1519
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore/CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.csproj" Id="a8d758ad-052e-4331-9bf7-280ea9a55981" />
1620
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.InMemory/CodeBeam.UltimateAuth.Authentication.InMemory.csproj" Id="bd87e254-0565-4fc5-950d-ee5bbb416079" />
1721
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Contracts/CodeBeam.UltimateAuth.Authorization.Contracts.csproj" Id="40a23002-f885-42a8-bdd9-fd962ab28742" />
18-
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" Id="8572d1e8-db32-42a1-b61c-e8805e59c019">
19-
<Build Solution="Debug|*" Project="false" />
20-
</Project>
22+
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" Id="8572d1e8-db32-42a1-b61c-e8805e59c019" />
2123
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.InMemory/CodeBeam.UltimateAuth.Authorization.InMemory.csproj" Id="a1e6d007-bdc0-4574-b549-ec863757edd3" />
2224
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Reference/CodeBeam.UltimateAuth.Authorization.Reference.csproj" Id="84b784d0-bb48-406a-a0d1-c600da667597" />
2325
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization/CodeBeam.UltimateAuth.Authorization.csproj" Id="28b1d647-fb0b-4cc3-8503-2680c4a9b28f" />
@@ -30,19 +32,15 @@
3032
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.InMemory/CodeBeam.UltimateAuth.Credentials.InMemory.csproj" Id="62ee7b1d-46ce-4f2e-985d-1e794f891b8b" />
3133
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.Reference/CodeBeam.UltimateAuth.Credentials.Reference.csproj" Id="ca03a140-f3dc-4a21-9b7d-895a3b10808b" />
3234
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials/CodeBeam.UltimateAuth.Credentials.csproj" Id="2281c3b5-1d60-4542-a673-553f96eed25b" />
33-
<Project Path="src/persistence/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions.csproj" Id="8867767d-bd1b-4d51-ac3f-0979038165c9">
34-
<Build Solution="Debug|*" Project="false" />
35-
</Project>
35+
<Project Path="src/persistence/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions.csproj" Id="8867767d-bd1b-4d51-ac3f-0979038165c9" />
3636
<Project Path="src/policies/CodeBeam.UltimateAuth.Policies/CodeBeam.UltimateAuth.Policies.csproj" Id="b37c337f-2446-4f54-8684-b72fa83ac444" />
3737
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
3838
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" Id="5b9a090d-1689-4a81-9dfa-3ba69f0bda38" />
3939
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.InMemory/CodeBeam.UltimateAuth.Sessions.InMemory.csproj" Id="fc9bfef0-8a89-4639-81ee-3f84f6e33816" />
4040
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore/CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.csproj" Id="6eb14b32-0b56-460f-a2b2-f95d28bad625" />
4141
<Project Path="src/tokens/CodeBeam.UltimateAuth.Tokens.InMemory/CodeBeam.UltimateAuth.Tokens.InMemory.csproj" Id="8220884e-4958-4b49-8c69-56ce9d2b6c6f" />
4242
<Project Path="src/users/CodeBeam.UltimateAuth.Users.Contracts/CodeBeam.UltimateAuth.Users.Contracts.csproj" Id="3a04f065-8f9d-46b3-9726-1febffe6d46f" />
43-
<Project Path="src/users/CodeBeam.UltimateAuth.Users.EntityFrameworkCore/CodeBeam.UltimateAuth.Users.EntityFrameworkCore.csproj" Id="a8febfee-0cfe-4e8c-8dcb-8703c35dd77b">
44-
<Build Solution="Debug|*" Project="false" />
45-
</Project>
43+
<Project Path="src/users/CodeBeam.UltimateAuth.Users.EntityFrameworkCore/CodeBeam.UltimateAuth.Users.EntityFrameworkCore.csproj" Id="a8febfee-0cfe-4e8c-8dcb-8703c35dd77b" />
4644
<Project Path="src/users/CodeBeam.UltimateAuth.Users.InMemory/CodeBeam.UltimateAuth.Users.InMemory.csproj" Id="7ce3df22-4773-4b9b-afd0-8ba506e0f9de" />
4745
<Project Path="src/users/CodeBeam.UltimateAuth.Users.Reference/CodeBeam.UltimateAuth.Users.Reference.csproj" Id="601176dd-b760-4b6f-9cc7-c618134ae178" />
4846
<Project Path="src/users/CodeBeam.UltimateAuth.Users/CodeBeam.UltimateAuth.Users.csproj" Id="30d5db36-6dc8-46f6-9139-8b6b3d6053d5" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<Version>0.1.0-preview.1</Version>
8+
<InformationalVersion>0.1.0-preview.1</InformationalVersion>
9+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore\CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.csproj" />
14+
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore\CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" />
15+
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
16+
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore\CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore.csproj" />
17+
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.Reference\CodeBeam.UltimateAuth.Credentials.Reference.csproj" />
18+
<ProjectReference Include="..\..\src\sessions\CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore\CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" />
19+
<ProjectReference Include="..\..\src\tokens\CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore\CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.csproj" />
20+
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.EntityFrameworkCore\CodeBeam.UltimateAuth.Users.EntityFrameworkCore.csproj" />
21+
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.Reference\CodeBeam.UltimateAuth.Users.Reference.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace CodeBeam.UltimateAuth.EntityFrameworkCore
4+
{
5+
/// <summary>
6+
/// Provides configuration options for setting up Entity Framework Core database contexts used by the UltimateAuth
7+
/// system.
8+
/// </summary>
9+
/// <remarks>Use this class to specify delegates that configure the options for various DbContext
10+
/// instances, such as Users, Credentials, Authorization, Sessions, Tokens, and Authentication. Each property allows
11+
/// customization of the corresponding context's setup, including database provider and connection details. If a
12+
/// specific configuration delegate is not set for a context, the default configuration is applied. This class is
13+
/// typically configured during application startup to ensure consistent and flexible database context
14+
/// initialization.</remarks>
15+
public sealed class UAuthEfCoreOptions
16+
{
17+
/// <summary>
18+
/// Gets or sets the default action to configure the database context options builder.
19+
/// </summary>
20+
/// <remarks>Use this property to specify a delegate that applies default configuration to a
21+
/// DbContextOptionsBuilder instance. This action is typically invoked when setting up a new database context to
22+
/// ensure consistent configuration across the application.</remarks>
23+
public Action<DbContextOptionsBuilder>? Default { get; set; }
24+
25+
26+
/// <summary>
27+
/// Gets or sets the delegate used to configure options for the Users DbContext.
28+
/// If not set, default option will implement.
29+
/// </summary>
30+
/// <remarks>Assign a delegate to customize the configuration of the Users DbContext, such as
31+
/// specifying the database provider or connection string. This property is typically used during application
32+
/// startup to control how the Users context is set up.</remarks>
33+
public Action<DbContextOptionsBuilder>? Users { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the delegate used to configure options for the Credentials DbContext.
37+
/// If not set, default option will implement.
38+
/// </summary>
39+
/// <remarks>Assign a delegate to customize the configuration of the Credentials DbContext, such as
40+
/// specifying the database provider or connection string. This property is typically used during application
41+
/// startup to control how the Credentials context is set up.</remarks>
42+
public Action<DbContextOptionsBuilder>? Credentials { get; set; }
43+
44+
/// <summary>
45+
/// Gets or sets the delegate used to configure options for the Authorization DbContext.
46+
/// If not set, default option will implement.
47+
/// </summary>
48+
/// <remarks>Assign a delegate to customize the configuration of the Authorization DbContext, such as
49+
/// specifying the database provider or connection string. This property is typically used during application
50+
/// startup to control how the Authorization context is set up.</remarks>
51+
public Action<DbContextOptionsBuilder>? Authorization { get; set; }
52+
53+
/// <summary>
54+
/// Gets or sets the delegate used to configure options for the Sessions DbContext.
55+
/// If not set, default option will implement.
56+
/// </summary>
57+
/// <remarks>Assign a delegate to customize the configuration of the Sessions DbContext, such as
58+
/// specifying the database provider or connection string. This property is typically used during application
59+
/// startup to control how the Sessions context is set up.</remarks>
60+
public Action<DbContextOptionsBuilder>? Sessions { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the delegate used to configure options for the Tokens DbContext.
64+
/// If not set, default option will implement.
65+
/// </summary>
66+
/// <remarks>Assign a delegate to customize the configuration of the Tokens DbContext, such as
67+
/// specifying the database provider or connection string. This property is typically used during application
68+
/// startup to control how the Tokens context is set up.</remarks>
69+
public Action<DbContextOptionsBuilder>? Tokens { get; set; }
70+
71+
/// <summary>
72+
/// Gets or sets the delegate used to configure options for the Authentication DbContext.
73+
/// If not set, default option will implement.
74+
/// </summary>
75+
/// <remarks>Assign a delegate to customize the configuration of the Authentication DbContext, such as
76+
/// specifying the database provider or connection string. This property is typically used during application
77+
/// startup to control how the Authentication context is set up.</remarks>
78+
public Action<DbContextOptionsBuilder>? Authentication { get; set; }
79+
80+
internal Action<DbContextOptionsBuilder> Resolve(Action<DbContextOptionsBuilder>? specific)
81+
=> specific ?? Default ?? throw new InvalidOperationException("No database configuration provided for UltimateAuth EFCore. Use options.Default or configure specific DbContext options.");
82+
}
83+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.Extensions;
2+
using CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.Extensions;
3+
using CodeBeam.UltimateAuth.Authorization.Reference.Extensions;
4+
using CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore.Extensions;
5+
using CodeBeam.UltimateAuth.Credentials.Reference.Extensions;
6+
using CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.Extensions;
7+
using CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.Extensions;
8+
using CodeBeam.UltimateAuth.Users.EntityFrameworkCore.Extensions;
9+
using CodeBeam.UltimateAuth.Users.Reference.Extensions;
10+
using Microsoft.EntityFrameworkCore;
11+
using Microsoft.Extensions.DependencyInjection;
12+
13+
namespace CodeBeam.UltimateAuth.EntityFrameworkCore;
14+
15+
/// <summary>
16+
/// Provides extension methods for registering UltimateAuth with Entity Framework Core-based persistence using reference
17+
/// domain implementations.
18+
/// </summary>
19+
public static class UltimateAuthEntityFrameworkCoreExtensions
20+
{
21+
/// <summary>
22+
/// Registers UltimateAuth with Entity Framework Core based persistence using reference domain implementations.
23+
/// </summary>
24+
/// <param name="services">The service collection.</param>
25+
/// <param name="configureDb">
26+
/// A delegate used to configure the <see cref="DbContextOptionsBuilder"/> for all UltimateAuth DbContexts.
27+
///
28+
/// This is required and must specify a database provider such as:
29+
/// <list type="bullet">
30+
/// <item><description>UseSqlServer</description></item>
31+
/// <item><description>UseNpgsql</description></item>
32+
/// <item><description>UseSqlite</description></item>
33+
/// </list>
34+
/// </param>
35+
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
36+
/// <remarks>
37+
/// This method wires up all Entity Framework Core stores along with reference domain implementations.
38+
///
39+
/// Example:
40+
/// <code>
41+
/// services.AddUltimateAuthServer()
42+
/// .AddEntityFrameworkReference(options =>
43+
/// {
44+
/// options.UseSqlServer("connection-string");
45+
/// });
46+
/// </code>
47+
///
48+
/// Note:
49+
/// This method does not configure migrations automatically. You are responsible for managing migrations.
50+
/// </remarks>
51+
public static IServiceCollection AddEntityFrameworkReference(this IServiceCollection services, Action<DbContextOptionsBuilder> configureDb)
52+
{
53+
services
54+
.AddUltimateAuthUsersEntityFrameworkCore(configureDb)
55+
.AddUltimateAuthUsersReference()
56+
.AddUltimateAuthCredentialsEntityFrameworkCore(configureDb)
57+
.AddUltimateAuthCredentialsReference()
58+
.AddUltimateAuthAuthorizationEntityFrameworkCore(configureDb)
59+
.AddUltimateAuthAuthorizationReference()
60+
.AddUltimateAuthSessionsEntityFrameworkCore(configureDb)
61+
.AddUltimateAuthTokensEntityFrameworkCore(configureDb)
62+
.AddUltimateAuthAuthenticationEntityFrameworkCore(configureDb);
63+
64+
return services;
65+
}
66+
67+
/// <summary>
68+
/// Adds and configures Entity Framework Core-based UltimateAuth services and related references to the specified
69+
/// service collection.
70+
/// </summary>
71+
/// <remarks>This method registers all required UltimateAuth services for users, credentials,
72+
/// authorization, sessions, tokens, and authentication using Entity Framework Core. It should be called during
73+
/// application startup as part of service configuration.</remarks>
74+
/// <param name="services">The service collection to which the UltimateAuth Entity Framework Core services and references will be added.</param>
75+
/// <param name="configure">A delegate that configures the options for UltimateAuth Entity Framework Core integration.</param>
76+
/// <returns>The same service collection instance, enabling method chaining.</returns>
77+
public static IServiceCollection AddEntityFrameworkReference(this IServiceCollection services, Action<UAuthEfCoreOptions> configure)
78+
{
79+
var options = new UAuthEfCoreOptions();
80+
configure(options);
81+
82+
services
83+
.AddUltimateAuthUsersEntityFrameworkCore(options.Resolve(options.Users))
84+
.AddUltimateAuthUsersReference()
85+
.AddUltimateAuthCredentialsEntityFrameworkCore(options.Resolve(options.Credentials))
86+
.AddUltimateAuthCredentialsReference()
87+
.AddUltimateAuthAuthorizationEntityFrameworkCore(options.Resolve(options.Authorization))
88+
.AddUltimateAuthAuthorizationReference()
89+
.AddUltimateAuthSessionsEntityFrameworkCore(options.Resolve(options.Sessions))
90+
.AddUltimateAuthTokensEntityFrameworkCore(options.Resolve(options.Tokens))
91+
.AddUltimateAuthAuthenticationEntityFrameworkCore(options.Resolve(options.Authentication));
92+
93+
return services;
94+
}
95+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<Version>0.1.0-preview.1</Version>
8+
<InformationalVersion>0.1.0-preview.1</InformationalVersion>
9+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.InMemory\CodeBeam.UltimateAuth.Authentication.InMemory.csproj" />
14+
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.InMemory\CodeBeam.UltimateAuth.Authorization.InMemory.csproj" />
15+
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
16+
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.InMemory\CodeBeam.UltimateAuth.Credentials.InMemory.csproj" />
17+
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.Reference\CodeBeam.UltimateAuth.Credentials.Reference.csproj" />
18+
<ProjectReference Include="..\..\src\sessions\CodeBeam.UltimateAuth.Sessions.InMemory\CodeBeam.UltimateAuth.Sessions.InMemory.csproj" />
19+
<ProjectReference Include="..\..\src\tokens\CodeBeam.UltimateAuth.Tokens.InMemory\CodeBeam.UltimateAuth.Tokens.InMemory.csproj" />
20+
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.InMemory\CodeBeam.UltimateAuth.Users.InMemory.csproj" />
21+
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.Reference\CodeBeam.UltimateAuth.Users.Reference.csproj" />
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)