Skip to content

Commit 79de220

Browse files
committed
fix
1 parent c20914d commit 79de220

File tree

14 files changed

+189
-109
lines changed

14 files changed

+189
-109
lines changed

RoyalCode.EnterprisePatterns/RoyalCode.Events.Outbox.Abstractions/RoyalCode.Events.Outbox.Abstractions.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Description>
1111
Abstract components for the Outbox Pattern.
1212
</Description>
13-
<PackageTags>RoyalCode Enterprise-Patterns Outbox Outbox-Pattern</PackageTags>
13+
<PackageTags>RoyalCode Enterprise-Patterns Events Outbox Outbox-Pattern</PackageTags>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

RoyalCode.EnterprisePatterns/RoyalCode.Events.Outbox.Api/RoyalCode.Events.Outbox.Api.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Description>
1111
AspNetCore WebApi's for the Outbox Pattern.
1212
</Description>
13-
<PackageTags>RoyalCode Enterprise-Patterns Outbox Outbox-Pattern</PackageTags>
13+
<PackageTags>RoyalCode Enterprise-Patterns Events Outbox Outbox-Pattern</PackageTags>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

RoyalCode.EnterprisePatterns/RoyalCode.Events.Outbox.EntityFramework.Postgres/RoyalCode.Events.Outbox.EntityFramework.Postgres.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<AssemblyVersion>$(MsgVer)</AssemblyVersion>
99
<FileVersion>$(MsgVer)</FileVersion>
1010
<Description>
11-
Components for the Outbox Pattern implemented with EntityFrameworkCore.
11+
PostgreSQL mappings for components of the Outbox Pattern implemented with EntityFrameworkCore.
1212
</Description>
13-
<PackageTags>RoyalCode Enterprise-Patterns Outbox Outbox-Pattern</PackageTags>
13+
<PackageTags>RoyalCode Enterprise-Patterns Events Outbox Outbox-Pattern</PackageTags>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

RoyalCode.EnterprisePatterns/RoyalCode.Events.Outbox.EntityFramework/RoyalCode.Events.Outbox.EntityFramework.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<AssemblyVersion>$(MsgVer)</AssemblyVersion>
99
<FileVersion>$(MsgVer)</FileVersion>
1010
<Description>
11-
PostgreSQL mappings for components of the Outbox Pattern implemented with EntityFrameworkCore.
11+
Components for the Outbox Pattern implemented with EntityFrameworkCore.
1212
</Description>
13-
<PackageTags>RoyalCode Enterprise-Patterns Outbox Outbox-Pattern</PackageTags>
13+
<PackageTags>RoyalCode Enterprise-Patterns Events Outbox Outbox-Pattern</PackageTags>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

RoyalCode.EnterprisePatterns/RoyalCode.UnitOfWork.EntityFramework/Extensions/PersistenceServiceCollectionExtensions.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ public static IUnitOfWorkBuilder<TDbContext> AddUnitOfWork<TDbContext>(
2626
where TDbContext : DbContext
2727
{
2828
services.TryAdd(ServiceDescriptor.Describe(
29-
typeof(IUnitOfWork),
29+
typeof(IUnitOfWork<TDbContext>),
3030
typeof(UnitOfWork<>).MakeGenericType(typeof(TDbContext)),
3131
lifetime));
3232

33+
services.TryAdd(ServiceDescriptor.Describe(
34+
typeof(IUnitOfWork),
35+
sp => sp.GetService<IUnitOfWork<TDbContext>>()!,
36+
lifetime));
37+
3338
return new UnitOfWorkBuilder<TDbContext>(services, lifetime);
3439
}
3540
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using RoyalCode.UnitOfWork.Abstractions;
3+
4+
namespace RoyalCode.UnitOfWork.EntityFramework;
5+
6+
#pragma warning disable S2326 // TDbContext
7+
8+
/// <summary>
9+
/// A unit of work that will be implemented by the <see cref='DbContext'/> defined by <typeparamref name='TDbContext'/>.
10+
/// </summary>
11+
/// <typeparam name="TDbContext">The DbContext type.</typeparam>
12+
public interface IUnitOfWork<TDbContext> : IUnitOfWork
13+
where TDbContext: DbContext
14+
{ }

RoyalCode.EnterprisePatterns/RoyalCode.UnitOfWork.EntityFramework/IUnitOfWorkBuilder.cs

+38-6
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,72 @@ public interface IUnitOfWorkBuilder<out TDbContext> : IUnitOfWorkBuilder
4343
/// </summary>
4444
/// <param name="configurer">Action to configure.</param>
4545
/// <returns>The same instance.</returns>
46-
IUnitOfWorkBuilder<TDbContext> ConfigureDbContextPool(Action<DbContextOptionsBuilder> configurer);
46+
IUnitOfWorkBuilder<TDbContext> ConfigureDbContextPool(Action<DbContextOptionsBuilder> configurer)
47+
{
48+
ArgumentNullException.ThrowIfNull(configurer);
49+
Services.AddDbContextPool<TDbContext>(configurer);
50+
return this;
51+
}
4752

4853
/// <summary>
4954
/// Configure the <see cref="DbContext"/> for the unit of work as pooled.
5055
/// </summary>
5156
/// <param name="configurer">Action to configure.</param>
5257
/// <returns>The same instance.</returns>
53-
IUnitOfWorkBuilder<TDbContext> ConfigureDbContextPool(Action<IServiceProvider, DbContextOptionsBuilder> configurer);
58+
IUnitOfWorkBuilder<TDbContext> ConfigureDbContextPool(Action<IServiceProvider, DbContextOptionsBuilder> configurer)
59+
{
60+
ArgumentNullException.ThrowIfNull(configurer);
61+
Services.AddDbContextPool<TDbContext>(configurer);
62+
return this;
63+
}
5464

5565
/// <summary>
5666
/// Configure the <see cref="DbContext"/> for the unit of work..
5767
/// </summary>
5868
/// <param name="configurer">Action to configure.</param>
5969
/// <returns>The same instance.</returns>
60-
IUnitOfWorkBuilder<TDbContext> ConfigureDbContext(Action<DbContextOptionsBuilder> configurer);
70+
IUnitOfWorkBuilder<TDbContext> ConfigureDbContext(Action<DbContextOptionsBuilder> configurer)
71+
{
72+
ArgumentNullException.ThrowIfNull(configurer);
73+
Services.AddDbContext<TDbContext>(configurer, Lifetime);
74+
return this;
75+
}
6176

6277
/// <summary>
6378
/// Configure the <see cref="DbContext"/> for the unit of work..
6479
/// </summary>
6580
/// <param name="configurer">Action to configure.</param>
6681
/// <returns>The same instance.</returns>
67-
IUnitOfWorkBuilder<TDbContext> ConfigureDbContext(Action<IServiceProvider, DbContextOptionsBuilder> configurer);
82+
IUnitOfWorkBuilder<TDbContext> ConfigureDbContext(Action<IServiceProvider, DbContextOptionsBuilder> configurer)
83+
{
84+
ArgumentNullException.ThrowIfNull(configurer);
85+
Services.AddDbContext<TDbContext>(configurer, Lifetime);
86+
return this;
87+
}
6888

6989
/// <summary>
7090
/// Configure the repositories for the unit of work.
7191
/// </summary>
7292
/// <param name="configureAction">Action to configure.</param>
7393
/// <returns>The same instance.</returns>
74-
IUnitOfWorkBuilder<TDbContext> ConfigureRepositories(Action<IRepositoriesBuilder<TDbContext>> configureAction);
94+
IUnitOfWorkBuilder<TDbContext> ConfigureRepositories(Action<IRepositoriesBuilder<TDbContext>> configureAction)
95+
{
96+
ArgumentNullException.ThrowIfNull(configureAction);
97+
var repositoryConfigurer = new RepositoriesBuilder<TDbContext>(Services, Lifetime);
98+
configureAction(repositoryConfigurer);
99+
return this;
100+
}
75101

76102
/// <summary>
77103
/// Configure the searches for the unit of work.
78104
/// </summary>
79105
/// <param name="configureAction">Action to configure.</param>
80106
/// <returns>The same instance.</returns>
81-
IUnitOfWorkBuilder<TDbContext> ConfigureSearches(Action<ISearchConfigurations<TDbContext>> configureAction);
107+
IUnitOfWorkBuilder<TDbContext> ConfigureSearches(Action<ISearchConfigurations<TDbContext>> configureAction)
108+
{
109+
ArgumentNullException.ThrowIfNull(configureAction);
110+
var configurations = new SearchConfigurations<TDbContext>(Services);
111+
configureAction(configurations);
112+
return this;
113+
}
82114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace RoyalCode.UnitOfWork.EntityFramework.Internals;
5+
6+
/// <summary>
7+
/// <para>
8+
/// Internal default implementation of <see cref="IUnitOfWorkBuilder{TDbContext}"/>.
9+
/// </para>
10+
/// </summary>
11+
/// <typeparam name="TDbContext">The type of the <see cref="DbContext"/>.</typeparam>
12+
public sealed class UnitOfWorkBuilder<TDbContext> : IUnitOfWorkBuilder<TDbContext>
13+
where TDbContext : DbContext
14+
{
15+
/// <summary>
16+
/// Creates a new builder.
17+
/// </summary>
18+
/// <param name="services">The service collection.</param>
19+
/// <param name="lifetime">The lifetime that will be used when register services.</param>
20+
public UnitOfWorkBuilder(
21+
IServiceCollection services,
22+
ServiceLifetime lifetime)
23+
{
24+
Services = services;
25+
Lifetime = lifetime;
26+
}
27+
28+
/// <inheritdoc />
29+
public IServiceCollection Services { get; }
30+
31+
/// <inheritdoc />
32+
public ServiceLifetime Lifetime { get; }
33+
}

RoyalCode.EnterprisePatterns/RoyalCode.UnitOfWork.EntityFramework/UnitOfWork.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace RoyalCode.UnitOfWork.EntityFramework;
1414
/// Type of the <see cref="DbContext"/> that contains the mapped entities referring to the work unit context.
1515
/// </para>
1616
/// </typeparam>
17-
public class UnitOfWork<TDbContext> : IUnitOfWork, ITransaction
17+
public class UnitOfWork<TDbContext> : IUnitOfWork<TDbContext>, ITransaction
1818
where TDbContext : DbContext
1919
{
2020
private IDbContextTransaction? dbContextTransaction;

RoyalCode.EnterprisePatterns/RoyalCode.UnitOfWork.EntityFramework/UnitOfWorkBuilder.cs

-86
This file was deleted.

RoyalCode.EnterprisePatterns/RoyalCode.WorkContext.Abstractions/IWorkContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ namespace RoyalCode.WorkContext.Abstractions;
2525
/// and the services that are provided is part of the persistence unit.
2626
/// </para>
2727
/// </summary>
28-
public interface IWorkContext : IUnitOfWork, IEntityManager, ISearchable, IHintsContainer, IInfrastructureProvidesServices { }
28+
public interface IWorkContext : IUnitOfWork, IEntityManager, ISearchManager, IHintsContainer, IInfrastructureProvidesServices { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using RoyalCode.WorkContext.Abstractions;
3+
4+
namespace RoyalCode.WorkContext.EntityFramework;
5+
6+
#pragma warning disable S2326 // TDbContext
7+
8+
/// <summary>
9+
/// A <see cref='IWorkContext'/> that is implemented with <see cref='DbContext'/> of type <typeparamref name='TDbContext'/>.
10+
/// </summary>
11+
/// <typeparam name="TDbContext"></typeparam>
12+
public interface IWorkContext<TDbContext> : IWorkContext
13+
where TDbContext: DbContext
14+
{ }

RoyalCode.EnterprisePatterns/RoyalCode.WorkContext.EntityFramework/WorkContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace RoyalCode.WorkContext.EntityFramework;
1515
/// to resolve the repositories and searches.
1616
/// </summary>
1717
/// <typeparam name="TDbContext">The type of the database context.</typeparam>
18-
public class WorkContext<TDbContext> : UnitOfWork<TDbContext>, IWorkContext
18+
public class WorkContext<TDbContext> : UnitOfWork<TDbContext>, IWorkContext<TDbContext>
1919
where TDbContext : DbContext
2020
{
2121
private readonly IServiceProvider serviceProvider;
@@ -51,7 +51,7 @@ public IAllEntities<TEntity> All<TEntity>() where TEntity : class
5151
}
5252

5353
/// <inheritdoc />
54-
public ISearch<TEntity> CreateSearch<TEntity>() where TEntity : class
54+
public ISearch<TEntity> Search<TEntity>() where TEntity : class
5555
{
5656
var search = serviceProvider.GetService<Searches.Persistence.EntityFramework.Internals.ISearch<TDbContext, TEntity>>();
5757
return search is null

0 commit comments

Comments
 (0)