-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved asp.net stuff in separate project to prevent unneeded dependenc…
…y on asp.net.
- Loading branch information
1 parent
8edfd03
commit b35f4ca
Showing
21 changed files
with
229 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using DotNetElements.Core; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace DotNetElements.AspNetCore; | ||
|
||
public class CurrentUserProviderWeb : ICurrentUserProvider | ||
{ | ||
private readonly IHttpContextAccessor contextAccessor; | ||
|
||
public CurrentUserProviderWeb(IHttpContextAccessor contextAccessor) | ||
{ | ||
this.contextAccessor = contextAccessor; | ||
} | ||
|
||
// todo | ||
public Guid GetCurrentUserId() | ||
{ | ||
return new Guid("FF4F759C-0916-4611-9B66-306543A51B2A"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<!-- ToDo remove if issue https://github.com/dotnet/sdk/issues/36666 is resolved in newer SDK release --> | ||
<EnableSourceControlManagerQueries>true</EnableSourceControlManagerQueries> | ||
<UseArtifactsOutput>true</UseArtifactsOutput> | ||
</PropertyGroup> | ||
</Project> |
21 changes: 21 additions & 0 deletions
21
src/DotNetElements.AspNetCore/DotNetElements.AspNetCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DotNetElements.Core\DotNetElements.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
35 changes: 35 additions & 0 deletions
35
src/DotNetElements.AspNetCore/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using DotNetElements.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace DotNetElements.AspNetCore.Extensions; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IReadOnlyList<IModule>? RegisteredModules { get; private set; } | ||
|
||
public static IServiceCollection RegisterModules(this IServiceCollection services, Assembly moduleAssembly) | ||
{ | ||
IEnumerable<IModule> modules = DiscoverModules(moduleAssembly); | ||
List<IModule> registeredModules = []; | ||
|
||
foreach (IModule module in modules) | ||
{ | ||
module.RegisterModules(services); | ||
registeredModules.Add(module); | ||
} | ||
|
||
RegisteredModules = registeredModules; | ||
|
||
return services; | ||
} | ||
|
||
// todo replace with source generated version | ||
private static IEnumerable<IModule> DiscoverModules(Assembly moduleAssembly) | ||
{ | ||
return moduleAssembly.GetTypes() | ||
.Where(p => p.IsAssignableTo(typeof(IModule)) && p.IsClass && !p.IsAbstract) | ||
.Select(Activator.CreateInstance) | ||
.Cast<IModule>(); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...nsions/WebApplicationBuilderExtensions.cs → ...nsions/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...re/Extensions/WebApplicationExtensions.cs → ...re/Extensions/WebApplicationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using DotNetElements.Core; |
2 changes: 1 addition & 1 deletion
2
src/DotNetElements.Core/Core/IModule.cs → src/DotNetElements.AspNetCore/IModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/DotNetElements.Core/Core/ManagedReadOnlyRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System.Linq.Expressions; | ||
|
||
namespace DotNetElements.Core; | ||
|
||
public abstract class ManagedReadOnlyRepository<TRepository, TEntity, TKey> : IReadOnlyRepository<TEntity, TKey> | ||
where TEntity : Entity<TKey> | ||
where TKey : notnull, IEquatable<TKey> | ||
where TRepository : IReadOnlyRepository<TEntity, TKey> | ||
{ | ||
protected readonly IScopedRepositoryFactory<TRepository, TEntity, TKey> RepositoryFactory; | ||
|
||
public ManagedReadOnlyRepository(IScopedRepositoryFactory<TRepository, TEntity, TKey> repositoryFactory) | ||
{ | ||
this.RepositoryFactory = repositoryFactory; | ||
} | ||
|
||
public Task<IReadOnlyList<TEntity>> GetAllAsync(CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAllAsync(cancellationToken); | ||
} | ||
|
||
public Task<IReadOnlyList<TEntity>> GetAllFilteredAsync( | ||
Expression<Func<TEntity, bool>>? filter = null, | ||
Expression<Func<TEntity, object>>? orderBy = null, | ||
bool descending = true, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAllFilteredAsync(filter, orderBy, descending, cancellationToken); | ||
} | ||
|
||
public Task<IPagedList<TEntity>> GetAllPagedAsync( | ||
Expression<Func<TEntity, bool>>? filter = null, | ||
Expression<Func<TEntity, object>>? orderBy = null, | ||
bool descending = true, | ||
int page = 1, | ||
int pageSize = int.MaxValue, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAllPagedAsync(filter, orderBy, descending, page, pageSize, cancellationToken); | ||
} | ||
|
||
public Task<IPagedList<TProjection>> GetAllPagedWithProjectionAsync<TProjection>( | ||
Expression<Func<IQueryable<TEntity>, IQueryable<TProjection>>> selector, | ||
Expression<Func<TEntity, bool>>? filter = null, | ||
Expression<Func<TEntity, object>>? orderBy = null, | ||
bool descending = true, | ||
int page = 1, | ||
int pageSize = int.MaxValue, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAllPagedWithProjectionAsync(selector, filter, orderBy, descending, page, pageSize, cancellationToken); | ||
} | ||
|
||
public Task<IReadOnlyList<TProjection>> GetAllWithProjectionAsync<TProjection>( | ||
Expression<Func<IQueryable<TEntity>, | ||
IQueryable<TProjection>>> selector, | ||
Expression<Func<TEntity, bool>>? filter = null, | ||
Expression<Func<TEntity, object>>? orderBy = null, | ||
bool descending = true, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAllWithProjectionAsync(selector, filter, orderBy, descending, cancellationToken); | ||
} | ||
|
||
public Task<CrudResult<TEntity>> GetByIdAsync(TKey id, CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetByIdAsync(id, cancellationToken); | ||
} | ||
|
||
public Task<CrudResult<TEntity>> GetByIdFilteredAsync(TKey id, Expression<Func<TEntity, bool>>? filter = null, CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetByIdFilteredAsync(id, filter, cancellationToken); | ||
} | ||
|
||
public Task<CrudResult<TProjection>> GetByIdWithProjectionAsync<TProjection>( | ||
TKey id, | ||
Expression<Func<IQueryable<TEntity>, IQueryable<TProjection>>> selector, | ||
Expression<Func<TEntity, bool>>? filter = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetByIdWithProjectionAsync(id, selector, filter, cancellationToken); | ||
} | ||
|
||
public Task<CrudResult<AuditedModelDetails>> GetAuditedModelDetailsByIdAsync<TAuditedEntity>(TKey id, CancellationToken cancellationToken = default) | ||
where TAuditedEntity : AuditedEntity<TKey> | ||
{ | ||
using var repository = RepositoryFactory.Create(); | ||
|
||
return repository.Inner.GetAuditedModelDetailsByIdAsync<TAuditedEntity>(id, cancellationToken); | ||
} | ||
} |
Oops, something went wrong.