Skip to content

Commit 9bc2d9b

Browse files
committed
Remove generic repository pattern and related DI support
Removed BaseDbSetRepository and IRepository abstractions, along with DI registration logic in ServiceCollectionExtensions. Cleaned up related using statements. Minor formatting updates to exception constructors and reordered usings in Mediator files for clarity. This simplifies the codebase and removes the generic repository layer.
1 parent 154a19c commit 9bc2d9b

16 files changed

Lines changed: 34 additions & 469 deletions

File tree

Sources/EasyExtensions.AspNetCore/Exceptions/AccessDeniedException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace EasyExtensions.AspNetCore.Exceptions
1414
/// <param name="message">The error message that explains the reason for the exception. If not specified, a default message of "Access
1515
/// denied" is used.</param>
1616
public class AccessDeniedException(string objectName, string message = "Access denied")
17-
: WebApiException(HttpStatusCode.Forbidden, objectName, message) { }
17+
: WebApiException(HttpStatusCode.Forbidden, objectName, message)
18+
{ }
1819

1920
/// <summary>
2021
/// Represents an exception that is thrown when access to a resource of type T is denied, typically corresponding to
@@ -23,5 +24,6 @@ public class AccessDeniedException(string objectName, string message = "Access d
2324
/// <typeparam name="T">The type of the resource for which access was denied.</typeparam>
2425
/// <param name="message">The error message that describes the reason for the access denial.</param>
2526
public class AccessDeniedException<T>(string message = "Access denied")
26-
: AccessDeniedException(typeof(T).Name, message) { }
27+
: AccessDeniedException(typeof(T).Name, message)
28+
{ }
2729
}

Sources/EasyExtensions.AspNetCore/Exceptions/BadRequestException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ namespace EasyExtensions.AspNetCore.Exceptions
1212
/// error.</param>
1313
/// <param name="message">The error message that describes the reason for the bad request. The default is "Bad request".</param>
1414
public class BadRequestException(string objectName, string message = "Bad request")
15-
: WebApiException(HttpStatusCode.BadRequest, objectName, message) { }
15+
: WebApiException(HttpStatusCode.BadRequest, objectName, message)
16+
{ }
1617

1718
/// <summary>
1819
/// Represents an exception that is thrown to indicate a bad request error associated with a specific resource type.
1920
/// </summary>
2021
/// <typeparam name="T">The type of the resource or entity related to the bad request.</typeparam>
2122
/// <param name="message">The error message that describes the reason for the bad request. The default is "Bad request".</param>
2223
public class BadRequestException<T>(string message = "Bad request")
23-
: BadRequestException(typeof(T).Name, message) { }
24+
: BadRequestException(typeof(T).Name, message)
25+
{ }
2426
}

Sources/EasyExtensions.AspNetCore/Exceptions/DuplicateException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace EasyExtensions.AspNetCore.Exceptions
1414
/// <param name="objectName">The name of the object that caused the conflict.</param>
1515
/// <param name="message">The error message that describes the reason for the conflict. The default is "Object already exists."</param>
1616
public class DuplicateException(string objectName, string message = "Object already exists")
17-
: WebApiException(HttpStatusCode.Conflict, objectName, message) { }
17+
: WebApiException(HttpStatusCode.Conflict, objectName, message)
18+
{ }
1819

1920
/// <summary>
2021
/// Represents an exception that is thrown when an attempt is made to create or add a duplicate object of the
@@ -23,5 +24,6 @@ public class DuplicateException(string objectName, string message = "Object alre
2324
/// <typeparam name="T">The type of the object that caused the duplication error.</typeparam>
2425
/// <param name="message">The error message that explains the reason for the exception. The default is "Object already exists."</param>
2526
public class DuplicateException<T>(string message = "Object already exists")
26-
: DuplicateException(typeof(T).Name, message) { }
27+
: DuplicateException(typeof(T).Name, message)
28+
{ }
2729
}

Sources/EasyExtensions.AspNetCore/Exceptions/EntityNotFoundException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ namespace EasyExtensions.AspNetCore.Exceptions
1212
/// missing entity.</param>
1313
/// <param name="message">The error message that describes the reason for the exception. The default is "Entity was not found".</param>
1414
public class EntityNotFoundException(string objectName, string message = "Entity was not found")
15-
: WebApiException(HttpStatusCode.NotFound, objectName, message) { }
15+
: WebApiException(HttpStatusCode.NotFound, objectName, message)
16+
{ }
1617

1718
/// <summary>
1819
/// Represents an exception that is thrown when an entity of the specified type cannot be found.
1920
/// </summary>
2021
/// <typeparam name="T">The type of the entity that was not found.</typeparam>
2122
/// <param name="message">The error message that explains the reason for the exception. If not specified, a default message is used.</param>
2223
public class EntityNotFoundException<T>(string message = "Entity was not found")
23-
: EntityNotFoundException(typeof(T).Name, message) { }
24+
: EntityNotFoundException(typeof(T).Name, message)
25+
{ }
2426
}

Sources/EasyExtensions.AspNetCore/Exceptions/UnauthorizedException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace EasyExtensions.AspNetCore.Exceptions
1414
/// <param name="objectName">The name of the object or resource for which access was denied.</param>
1515
/// <param name="message">The error message that describes the reason for the unauthorized access. The default is "Unathorized".</param>
1616
public class UnauthorizedException(string objectName, string message = "Unathorized")
17-
: WebApiException(HttpStatusCode.Unauthorized, objectName, message) { }
17+
: WebApiException(HttpStatusCode.Unauthorized, objectName, message)
18+
{ }
1819

1920
/// <summary>
2021
/// Represents an exception that is thrown when an operation is attempted without the required authorization for a
@@ -23,5 +24,6 @@ public class UnauthorizedException(string objectName, string message = "Unathori
2324
/// <typeparam name="T">The type of the resource or entity for which authorization failed.</typeparam>
2425
/// <param name="message">The error message that explains the reason for the exception. The default is "Unathorized".</param>
2526
public class UnauthorizedException<T>(string message = "Unathorized")
26-
: UnauthorizedException(typeof(T).Name, message) { }
27+
: UnauthorizedException(typeof(T).Name, message)
28+
{ }
2729
}

Sources/EasyExtensions.EntityFrameworkCore/Abstractions/BaseEntity.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2025–2026 Vadim Belov <https://belov.us>
33

4-
using EasyExtensions.EntityFrameworkCore.Repository;
54
using System.ComponentModel.DataAnnotations;
65
using System.ComponentModel.DataAnnotations.Schema;
76

@@ -42,16 +41,5 @@ DateTime IAuditableEntity.UpdatedAt
4241
get => UpdatedAt;
4342
set => UpdatedAt = value;
4443
}
45-
46-
/// <summary>
47-
/// Update entity method is calling in <see cref="BaseDbSetRepository{TItem}.UpdateAsync(TItem, CancellationToken)"/>.
48-
/// Do not call this method from overriden method.
49-
/// </summary>
50-
/// <param name="entity">Entity to update.</param>
51-
/// <exception cref="NotImplementedException">Update method is not overriden in inherited class.</exception>
52-
public virtual void Update(BaseEntity<TId> entity)
53-
{
54-
throw new NotImplementedException("Update method is not overriden in inherited class.");
55-
}
5644
}
5745
}
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2025–2026 Vadim Belov <https://belov.us>
33

4-
using EasyExtensions.EntityFrameworkCore.Repository;
5-
using EasyExtensions.Helpers;
64
using Gridify;
75
using Microsoft.Extensions.DependencyInjection;
86
using System.Reflection;
@@ -23,22 +21,5 @@ public static IServiceCollection AddGridifyMappers(this IServiceCollection servi
2321
services.AddGridifyMappers(Assembly.GetCallingAssembly());
2422
return services;
2523
}
26-
27-
/// <summary>
28-
/// Adds all types that implement <see cref="IRepository"/> to the <see cref="IServiceCollection"/>.
29-
/// </summary>
30-
/// <param name="services"> The <see cref="IServiceCollection"/> instance. </param>
31-
/// <returns> Current <see cref="IServiceCollection"/> instance. </returns>
32-
public static IServiceCollection AddRepositories(this IServiceCollection services)
33-
{
34-
var repositories = ReflectionHelpers.GetTypesOfInterface<IRepository>();
35-
foreach (var repository in repositories)
36-
{
37-
Type genericType = repository.GetInterfaces().First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRepository<>));
38-
var descriptor = new ServiceDescriptor(genericType, repository, ServiceLifetime.Scoped);
39-
services.Add(descriptor);
40-
}
41-
return services;
42-
}
4324
}
4425
}

0 commit comments

Comments
 (0)