Skip to content

Commit

Permalink
Merge pull request #3 from RicardoZambon/fix/add-di
Browse files Browse the repository at this point in the history
fix: add dependency injection
  • Loading branch information
RicardoZambon authored Feb 20, 2024
2 parents abd816e + 85dee95 commit ac7668b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
27 changes: 27 additions & 0 deletions ZWebAPI/ExtensionMethods/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.DependencyInjection;
using ZDatabase.Entities.Audit;
using ZWebAPI.Services;
using ZWebAPI.Services.Interfaces;

namespace ZWebAPI.ExtensionMethods
{
/// <summary>
/// Extension methods for <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection"/>.
/// </summary>
public static class DependencyInjectionExtensions
{
/// <summary>
/// Adds the audit handler service to the service collection.
/// </summary>
/// <typeparam name="TAuditHandler">The type of the audit handler.</typeparam>
/// <param name="services">The services.</param>
/// <returns>The service collection.</returns>
public static IServiceCollection AddAuditService<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>(this IServiceCollection services)
where TServicesHistory : ServicesHistory<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>, new()
where TOperationsHistory : OperationsHistory<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>, new()
where TUsers : class
where TUsersKey : struct
=> services
.AddScoped<IAuditService<TUsers, TUsersKey>, AuditServiceDefault<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>>();
}
}
5 changes: 3 additions & 2 deletions ZWebAPI/Services/AuditServiceDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
using ZWebAPI.Interfaces;
using ZWebAPI.Models.Audit.OperationHistory;
using ZWebAPI.Models.Audit.ServiceHistory;
using ZWebAPI.Services.Interfaces;

namespace ZWebAPI.Services
{
/// <inheritdoc />
public class AuditServiceDefault<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>
public class AuditServiceDefault<TServicesHistory, TOperationsHistory, TUsers, TUsersKey> : IAuditService<TUsers, TUsersKey>
where TServicesHistory : ServicesHistory<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>, new()
where TOperationsHistory : OperationsHistory<TServicesHistory, TOperationsHistory, TUsers, TUsersKey>, new()
where TUsers : class
Expand All @@ -34,7 +35,7 @@ public class AuditServiceDefault<TServicesHistory, TOperationsHistory, TUsers, T
protected TServicesHistory? CurrentServiceHistory { get; private set; } = null;
#endregion

#region Constructor
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="AuditServiceDefault{TServicesHistory, TOperationsHistory, TUsers, TUsersKey}"/> class.
/// </summary>
Expand Down
48 changes: 48 additions & 0 deletions ZWebAPI/Services/Interfaces/IAuditService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.ChangeTracking;
using ZDatabase.Entities;
using ZWebAPI.Interfaces;
using ZWebAPI.Models.Audit.OperationHistory;
using ZWebAPI.Models.Audit.ServiceHistory;

namespace ZWebAPI.Services.Interfaces
{
/// <summary>
/// Service to handle audit services and operations.
/// </summary>
/// <typeparam name="TUsers">The type of the users.</typeparam>
/// <typeparam name="TUsersKey">The type of the users key.</typeparam>
public interface IAuditService<TUsers, TUsersKey>
where TUsers : class
where TUsersKey : struct
{
/// <summary>
/// Adds the operation history asynchronous.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="entityEntry">The entity entry.</param>
Task AddOperationHistoryAsync<TEntity>(EntityEntry<TEntity> entityEntry) where TEntity : AuditableEntity<TUsers, TUsersKey>;

/// <summary>
/// Begins a new service history asynchronous.
/// </summary>
Task BeginNewServiceHistoryAsync();

/// <summary>
/// Lists the operations history from the service history identifier.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="serviceHistoryID">The service history identifier.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>Query with all operations history from the service history identifier.</returns>
IQueryable<OperationsHistoryListModel> ListEntityOperationsHistory<TEntity>(long serviceHistoryID, IListParameters parameters) where TEntity : AuditableEntity<TUsers, TUsersKey>;

/// <summary>
/// Lists the services history from an entity identifier asynchronous.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="entityID">The entity identifier.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>Query with all services history from the entity identifier.</returns>
Task<IQueryable<ServicesHistoryListModel>> ListEntityServicesHistoryAsync<TEntity>(long entityID, IListParameters parameters) where TEntity : AuditableEntity<TUsers, TUsersKey>;
}
}

0 comments on commit ac7668b

Please sign in to comment.