Compare commits

...

21 Commits

Author SHA1 Message Date
d8d75829f0 Refactor ActionController to use MediatR
Updated `using` directives to include MediatR and related namespaces. Refactored `ActionController` to use constructor injection for `IMediator`. Modified the `Invoke` method to be asynchronous and replaced the placeholder `NotImplementedException` with a call to `mediator.InvokeRecAction(profileId)`. The method now returns an `Accepted` HTTP response to indicate successful request processing.
2025-11-25 17:15:25 +01:00
5697eb3dd8 Add InvokeRecActionCommandExtensions for ISender
Introduce a new static class `InvokeRecActionCommandExtensions`
to extend the `ISender` interface with the `InvokeRecAction`
method. This method simplifies the invocation of
`InvokeRecActionCommand` by allowing callers to pass only the
`profileId`, internally creating and sending the command.
2025-11-25 17:10:44 +01:00
2cf4d73cf3 Refactor InvokeRecActionQuery to InvokeRecActionCommand
Replaced the `InvokeRecActionQuery` class with the `InvokeRecActionCommand` class to better align with CQRS semantics. The new class retains the same `ProfileId` property and implements the `IRequest` interface. Updated the namespace to remain consistent.
2025-11-25 17:08:24 +01:00
495a5247bc Add InvokeRecActionQuery class for MediatR request
Introduced the `InvokeRecActionQuery` class in the `ReC.Application.RecActions.Commands` namespace to implement the Mediator pattern using the MediatR library.

- Added `using MediatR;` directive to include the library.
- Implemented `IRequest` interface in the new class.
- Added `ProfileId` property with `init` accessor for immutability.
- Organized the code under a new namespace for better structure.
2025-11-25 17:07:39 +01:00
5ba012cc13 Refactor infrastructure service setup
Renamed `AddInfrastructureServices` to `AddRecInfrastructure`
in both generic and non-generic forms to standardize naming
and improve clarity. Updated `Program.cs` to use the new
method, adding database context configuration with a
connection string from the app's configuration.

Added a constraint to `AddRecInfrastructure<TRecDbContext>`
requiring `TRecDbContext` to inherit from `RecDbContext`.
Refactored the method to register entities from the assembly
containing `RecAction`. Removed the old
`AddInfrastructureServices` method entirely.
2025-11-25 16:55:04 +01:00
89879d0821 Add services and update project configuration
Added `AddRecServices` and `AddInfrastructureServices` to `Program.cs` with necessary configurations. Updated `ReC.API.csproj` to include project references to `ReC.Application` and `ReC.Infrastructure`, and fixed an encoding issue by adding a BOM. Modified `appsettings.json` to include `MediatRLicense` and adjusted `AllowedHosts` format. Ensured `TargetFramework` and other project properties remain unchanged.
2025-11-25 16:52:21 +01:00
d62175f6ec Make LuckyPennySoftwareLicenseKey nullable
Updated the `LuckyPennySoftwareLicenseKey` property in the
`ConfigurationOptions` class to allow null values by changing
it from a non-nullable string with a default value of an empty
string to a nullable string (`string?`). This change enables
explicit representation of the absence of a license key using
`null` instead of an empty string.
2025-11-25 16:37:37 +01:00
a6cb0081ee Add DependencyInjection class for service registration
Introduced a new `DependencyInjection` class in the `ReC.Application` namespace to streamline service registration.

- Added `AddRecServices` extension method for `IServiceCollection` to configure AutoMapper and MediatR with assembly scanning.
- Included `ConfigurationOptions` class to allow configuration of a `LuckyPennySoftwareLicenseKey`.
- Added `using` directives for `Microsoft.Extensions.DependencyInjection` and `System.Reflection` to support dependency injection and assembly scanning.
2025-11-25 16:33:18 +01:00
7214b09640 Add AutoMapper and MediatR; implement DtoMappingProfile
Added `AutoMapper` and `MediatR` NuGet packages to the
`ReC.Application.csproj` file to include these libraries as
dependencies.

Created a `DtoMappingProfile` class in the `ReC.Application.Dto`
namespace to define a mapping configuration between the `RecAction`
entity and the `RecActionDto` data transfer object using `AutoMapper`.

Included necessary `using` directives for `AutoMapper` and
`ReC.Domain.Entities` in the `DtoMappingProfile.cs` file to enable
the mapping functionality.

These changes improve maintainability by automating object-to-object
mapping and prepare the project for potential use of the mediator
pattern with `MediatR`.
2025-11-25 15:38:53 +01:00
21d09df037 Add MediatR, RecActionDto, and ReadRecActionQuery
Added the `MediatR` NuGet package (v13.1.0) to enable the mediator pattern. Updated `ReC.Application.csproj` to include a project reference to `ReC.Domain`.

Introduced `RecActionDto` as a Data Transfer Object (DTO) for representing "RecAction" details, including properties for endpoints, authentication, and SQL connections.

Added `ReadRecActionQuery` to handle queries for retrieving `RecActionDto` objects, leveraging MediatR. This query filters results based on `ProfileId`.
2025-11-25 15:33:32 +01:00
eab38f1e34 Integrate EF Core with SQL Server and Infrastructure
Added `Microsoft.EntityFrameworkCore` and `ReC.Infrastructure` namespaces to `Program.cs` to enable EF Core functionality and infrastructure services. Configured the database context with a connection string from the app's configuration and added error handling for missing connection strings.

Updated `ReC.API.csproj` to include the `Microsoft.EntityFrameworkCore.SqlServer` NuGet package (v9.0.11) for SQL Server support. Added a project reference to `ReC.Infrastructure` to enable the API project to use the infrastructure layer.
2025-11-25 15:20:09 +01:00
e552658d2e Support generic DbContext in AddInfrastructureServices
Updated AddInfrastructureServices to support a generic
TRecDbContext type parameter, enabling the use of custom
DbContext types. Modified AddDbContext and AddDbRepository
to use the generic TRecDbContext type. Added an overload
of AddInfrastructureServices that defaults to RecDbContext
for backward compatibility. These changes enhance flexibility
and reusability while maintaining compatibility with existing
implementations.
2025-11-25 15:11:47 +01:00
d902cfb756 Enhance DI with repository registration support
Added `DigitalData.Core.Infrastructure` dependency and updated the `DependencyInjection` class to include `services.AddDbRepository` for dynamic repository registration from the `RecAction` assembly. Updated `ReC.Infrastructure.csproj` to include the new package reference. Improved dependency injection setup for better repository management.
2025-11-25 15:10:05 +01:00
cae3ec31c4 Add DI support for RecDbContext with configuration options
Introduced a `DependencyInjection` class with an extension
method `AddInfrastructureServices` to register `RecDbContext`
using configurable `DbContextOptions`. Added a `ConfigurationOptions`
class to encapsulate `DbContext` configuration.

Validated that `DbContextOptionsAction` is provided before
registration. Updated `ReC.Infrastructure.csproj` to include
`Microsoft.Extensions.Configuration.Abstractions` for enhanced
configuration support. Added necessary `using` directives.
2025-11-25 15:03:58 +01:00
1e22e4d851 Refactor Action class to RecAction
Replaced the `Action` class with a new `RecAction` class to represent the `VWREC_ACTION` database view. The `RecAction` class retains the same properties and annotations as the removed `Action` class, ensuring compatibility with the database schema.

Updated `RecDbContext` to use `RecAction`:
- Replaced `DbSet<Domain.Entities.Action>` with `DbSet<RecAction>`.
- Updated the `OnModelCreating` configuration to use `RecAction`.

This refactor improves clarity, aligns with naming conventions, and prepares the codebase for future changes.
2025-11-25 14:16:41 +01:00
163b5bc2f9 Add EF Core and RecDbContext for database integration
Added the `Microsoft.EntityFrameworkCore` NuGet package to the
`ReC.Infrastructure` project to enable database functionality.
Introduced `RecDbContext` with `DbSet` properties for `EndpointParam`,
`Action`, and `OutRes` entities. Configured `Action` as a keyless
entity in `OnModelCreating`. Added a project reference to
`ReC.Domain` to use domain entities in the infrastructure layer.
2025-11-25 14:15:06 +01:00
b94a620389 Rename Trigger method to Invoke in ActionController
The `Trigger` method in the `ActionController` class was renamed to `Invoke`. This change updates the HTTP POST endpoint that accepts a `profileId` as a route parameter. The method's functionality remains unchanged, as it still throws a `NotImplementedException`.
2025-11-25 13:44:31 +01:00
2af140db96 Add OutRes entity mapped to TBREC_OUT_RESULT table
A new `OutRes` class was added to represent the `TBREC_OUT_RESULT` table in the `dbo` schema. The class includes properties for `Id`, `ActionId`, `ResultHeader`, `ResultBody`, `AddedWho`, `AddedWhen`, `ChangedWho`, and `ChangedWhen`, all mapped to corresponding database columns using data annotations. The `System.ComponentModel.DataAnnotations` and `System.ComponentModel.DataAnnotations.Schema` namespaces were imported to support this configuration.
2025-11-25 13:38:47 +01:00
304970f47a Rename class VwRecAction to Action
Renamed the class `VwRecAction` to `Action` to simplify the name
and better align with naming conventions. The `[Table]` attribute
mapping to `VWREC_ACTION` in the `dbo` schema remains unchanged.
Class properties such as `ActionId` and `ProfileId` are unaffected
by this change.
2025-11-25 10:32:17 +01:00
c33144ad7b Add EndpointParam entity for database table mapping
Introduced the `EndpointParam` class to represent the `TBREC_CFG_ENDPOINT_PARAMS` table in the database.

- Added `using` directives for data annotations and table mapping.
- Defined properties to map to table columns, all nullable for flexibility.
- Annotated the class with `[Table]` and properties with `[Column]` attributes.
- Marked `Guid` as the primary key using the `[Key]` attribute.
- Documented the class with a summary explaining its purpose and design.

This change facilitates ORM integration and ensures schema flexibility.
2025-11-25 10:31:55 +01:00
3be1d04a43 Add VwRecAction class to map VWREC_ACTION database view
Introduced the `VwRecAction` class to represent the `VWREC_ACTION`
database view. The class is annotated with `[Table]` and `[Column]`
attributes for schema mapping and includes nullable properties to
handle potential schema changes gracefully. Added `using` directives
for data annotations and schema mapping. Documented the class to
explain its purpose and design decisions, ensuring flexibility and
resilience against database schema evolution.
2025-11-25 10:07:32 +01:00
16 changed files with 438 additions and 8 deletions

View File

@ -1,15 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.RecActions.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ActionController : ControllerBase
public class ActionController(IMediator mediator) : ControllerBase
{
[HttpPost("{profileId}")]
public Task<IActionResult> Trigger([FromRoute] int profileId)
public async Task<IActionResult> Invoke([FromRoute] int profileId)
{
// Implementation for retrieving actions would go here.
throw new NotImplementedException();
await mediator.InvokeRecAction(profileId);
return Accepted();
}
}

View File

@ -1,6 +1,24 @@
using Microsoft.EntityFrameworkCore;
using ReC.Infrastructure;
using ReC.Application;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRecServices(options =>
{
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
});
builder.Services.AddRecInfrastructure(options =>
{
options.ConfigureDbContext((dbContextOpt) =>
{
var connectionString = builder.Configuration.GetConnectionString("Default")
?? throw new InvalidOperationException("Connection string is not found.");
dbContextOpt.UseSqlServer(connectionString);
});
});
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -7,7 +7,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReC.Application\ReC.Application.csproj" />
<ProjectReference Include="..\ReC.Infrastructure\ReC.Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"MediatRLicense": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx1Y2t5UGVubnlTb2Z0d2FyZUxpY2Vuc2VLZXkvYmJiMTNhY2I1OTkwNGQ4OWI0Y2IxYzg1ZjA4OGNjZjkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2x1Y2t5cGVubnlzb2Z0d2FyZS5jb20iLCJhdWQiOiJMdWNreVBlbm55U29mdHdhcmUiLCJleHAiOiIxNzg0ODUxMjAwIiwiaWF0IjoiMTc1MzM2MjQ5MSIsImFjY291bnRfaWQiOiIwMTk4M2M1OWU0YjM3MjhlYmZkMzEwM2MyYTQ4NmU4NSIsImN1c3RvbWVyX2lkIjoiY3RtXzAxazB5NmV3MmQ4YTk4Mzg3aDJnbTRuOWswIiwic3ViX2lkIjoiLSIsImVkaXRpb24iOiIwIiwidHlwZSI6IjIifQ.ZqsFG7kv_-xGfxS6ACk3i0iuNiVUXX2AvPI8iAcZ6-z2170lGv__aO32tWpQccD9LCv5931lBNLWSblKS0MT3gOt-5he2TEftwiSQGFwoIBgtOHWsNRMinUrg2trceSp3IhyS3UaMwnxZDrCvx4-0O-kpOzVpizeHUAZNr5U7oSCWO34bpKdae6grtM5e3f93Z1vs7BW_iPgItd-aLvPwApbaG9VhmBTKlQ7b4Jh64y7UXJ9mKP7Qb_Oa97oEg0oY5DPHOWTZWeE1EzORgVr2qkK2DELSHuZ_EIUhODojkClPNAKtvEl_qEjpq0HZCIvGwfCCRlKlSkQqIeZdFkiXg"
}

View File

@ -0,0 +1,32 @@
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
namespace ReC.Application;
public static class DependencyInjection
{
public static IServiceCollection AddRecServices(this IServiceCollection services, Action<ConfigurationOptions> options)
{
var configOpt = new ConfigurationOptions();
options.Invoke(configOpt);
services.AddAutoMapper(cfg =>
{
cfg.AddMaps(Assembly.GetExecutingAssembly());
cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey;
});
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey;
});
return services;
}
public class ConfigurationOptions
{
public string? LuckyPennySoftwareLicenseKey { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using AutoMapper;
using ReC.Domain.Entities;
namespace ReC.Application.Dto;
public class DtoMappingProfile : Profile
{
public DtoMappingProfile()
{
CreateMap<RecAction, RecActionDto>();
}
}

View File

@ -0,0 +1,60 @@
namespace ReC.Application.Dto;
public class RecActionDto
{
public long? ActionId { get; init; }
public long? ProfileId { get; init; }
public string? ProfileName { get; init; }
public string? ProfileType { get; init; }
public byte? ProfileSequence { get; init; }
public long? EndpointId { get; init; }
public string? EndpointUri { get; init; }
public long? EndpointAuthId { get; init; }
public string? EndpointAuthType { get; init; }
public string? EndpointAuthApiKey { get; init; }
public string? EndpointAuthApiValue { get; init; }
public string? EndpointAuthApiKeyAddTo { get; init; }
public string? EndpointAuthToken { get; init; }
public string? EndpointAuthUsername { get; init; }
public string? EndpointAuthPassword { get; init; }
public string? EndpointAuthDomain { get; init; }
public string? EndpointAuthWorkstation { get; init; }
public short? EndpointParamsId { get; init; }
public short? SqlConnectionId { get; init; }
public string? SqlConnectionServer { get; init; }
public string? SqlConnectionDb { get; init; }
public string? SqlConnectionUsername { get; init; }
public string? SqlConnectionPassword { get; init; }
public string? RestType { get; init; }
public string? PreprocessingQuery { get; init; }
public string? HeaderQuery { get; init; }
public string? BodyQuery { get; init; }
public string? PostprocessingQuery { get; init; }
}

View File

@ -6,4 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="15.1.0" />
<PackageReference Include="MediatR" Version="13.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReC.Domain\ReC.Domain.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using MediatR;
namespace ReC.Application.RecActions.Commands;
public class InvokeRecActionCommand : IRequest
{
public int ProfileId { get; init; }
}
public static class InvokeRecActionCommandExtensions
{
public static Task InvokeRecAction(this ISender sender, int profileId)
=> sender.Send(new InvokeRecActionCommand { ProfileId = profileId });
}

View File

@ -0,0 +1,9 @@
using MediatR;
using ReC.Application.Dto;
namespace ReC.Application.RecActions.Queries;
public class ReadRecActionQuery : IRequest<IEnumerable<RecActionDto>>
{
public int ProfileId { get; init; }
}

View File

@ -0,0 +1,47 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
/// <summary>
/// Represents the TBREC_CFG_ENDPOINT_PARAMS table.
/// All properties are nullable to provide flexibility on the database side,
/// preventing breaking changes if columns are altered to be nullable in production.
/// </summary>
[Table("TBREC_CFG_ENDPOINT_PARAMS", Schema = "dbo")]
public class EndpointParam
{
[Key]
[Column("GUID")]
public long? Guid { get; set; }
[Column("ACTIVE")]
public bool? Active { get; set; }
[Column("DESCRIPTION")]
public string? Description { get; set; }
[Column("GROUP_ID")]
public short? GroupId { get; set; }
[Column("SEQUENCE")]
public byte? Sequence { get; set; }
[Column("KEY")]
public string? Key { get; set; }
[Column("VALUE")]
public string? Value { get; set; }
[Column("ADDED_WHO")]
public string? AddedWho { get; set; }
[Column("ADDED_WHEN")]
public DateTime? AddedWhen { get; set; }
[Column("CHANGED_WHO")]
public string? ChangedWho { get; set; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; set; }
}

View File

@ -0,0 +1,34 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_OUT_RESULT", Schema = "dbo")]
public class OutRes
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("GUID")]
public long? Id { get; set; }
[Column("ACTION_ID")]
public long? ActionId { get; set; }
[Column("RESULT_HEADER")]
public string? ResultHeader { get; set; }
[Column("RESULT_BODY")]
public string? ResultBody { get; set; }
[Column("ADDED_WHO")]
public string? AddedWho { get; set; }
[Column("ADDED_WHEN")]
public DateTime? AddedWhen { get; set; }
[Column("CHANGED_WHO")]
public string? ChangedWho { get; set; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; set; }
}

View File

@ -0,0 +1,117 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
/// <summary>
/// Represents the VWREC_ACTION view from the database.
///
/// All properties are defined as nullable to provide flexibility in case the underlying view
/// changes in production (e.g., columns added, removed, or modified). This approach prevents
/// runtime mapping errors and ensures the application can handle schema changes without
/// requiring immediate code updates.
/// </summary>
[Table("VWREC_ACTION", Schema = "dbo")]
public class RecAction
{
[Column("ACTION_ID")]
public long? ActionId { get; set; }
[Column("PROFILE_ID")]
public long? ProfileId { get; set; }
[Column("PROFILE_NAME")]
[MaxLength(100)]
public string? ProfileName { get; set; }
[Column("PROFILE_TYPE")]
[MaxLength(20)]
public string? ProfileType { get; set; }
[Column("PROFILE_SEQUENCE")]
public byte? ProfileSequence { get; set; }
[Column("ENDPOINT_ID")]
public long? EndpointId { get; set; }
[Column("ENDPOINT_URI")]
[MaxLength(4000)]
public string? EndpointUri { get; set; }
[Column("ENDPOINT_AUTH_ID")]
public long? EndpointAuthId { get; set; }
[Column("ENDPOINT_AUTH_TYPE")]
[MaxLength(50)]
public string? EndpointAuthType { get; set; }
[Column("ENDPOINT_AUTH_API_KEY")]
[MaxLength(300)]
public string? EndpointAuthApiKey { get; set; }
[Column("ENDPOINT_AUTH_API_VALUE")]
[MaxLength(300)]
public string? EndpointAuthApiValue { get; set; }
[Column("ENDPOINT_AUTH_API_KEY_ADD_TO")]
[MaxLength(20)]
public string? EndpointAuthApiKeyAddTo { get; set; }
[Column("ENDPOINT_AUTH_TOKEN")]
[MaxLength(300)]
public string? EndpointAuthToken { get; set; }
[Column("ENDPOINT_AUTH_USERNAME")]
[MaxLength(200)]
public string? EndpointAuthUsername { get; set; }
[Column("ENDPOINT_AUTH_PASSWORD")]
[MaxLength(200)]
public string? EndpointAuthPassword { get; set; }
[Column("ENDPOINT_AUTH_DOMAIN")]
[MaxLength(100)]
public string? EndpointAuthDomain { get; set; }
[Column("ENDPOINT_AUTH_WORKSTATION")]
[MaxLength(100)]
public string? EndpointAuthWorkstation { get; set; }
[Column("ENDPOINT_PARAMS_ID")]
public short? EndpointParamsId { get; set; }
[Column("SQL_CONNECTION_ID")]
public short? SqlConnectionId { get; set; }
[Column("SQL_CONNECTION_SERVER")]
[MaxLength(150)]
public string? SqlConnectionServer { get; set; }
[Column("SQL_CONNECTION_DB")]
[MaxLength(100)]
public string? SqlConnectionDb { get; set; }
[Column("SQL_CONNECTION_USERNAME")]
[MaxLength(100)]
public string? SqlConnectionUsername { get; set; }
[Column("SQL_CONNECTION_PASSWORD")]
[MaxLength(100)]
public string? SqlConnectionPassword { get; set; }
[Column("REST_TYPE")]
[MaxLength(20)]
public string? RestType { get; set; }
[Column("PREPROCESSING_QUERY")]
public string? PreprocessingQuery { get; set; }
[Column("HEADER_QUERY")]
public string? HeaderQuery { get; set; }
[Column("BODY_QUERY")]
public string? BodyQuery { get; set; }
[Column("POSTPROCESSING_QUERY")]
public string? PostprocessingQuery { get; set; }
}

View File

@ -0,0 +1,39 @@
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using ReC.Domain.Entities;
namespace ReC.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddRecInfrastructure<TRecDbContext>(this IServiceCollection services, Action<ConfigurationOptions> options)
where TRecDbContext : RecDbContext
{
var configOpt = new ConfigurationOptions();
options.Invoke(configOpt);
if(configOpt.DbContextOptionsAction is null)
throw new InvalidOperationException("DbContextOptionsAction must be configured.");
services.AddDbContext<RecDbContext>(configOpt.DbContextOptionsAction);
services.AddDbRepository(opt => opt.RegisterFromAssembly<TRecDbContext>(typeof(RecAction).Assembly));
return services;
}
public static IServiceCollection AddRecInfrastructure(this IServiceCollection services, Action<ConfigurationOptions> options)
=> services.AddRecInfrastructure<RecDbContext>(options);
public class ConfigurationOptions
{
internal Action<DbContextOptionsBuilder>? DbContextOptionsAction { get; private set; }
public ConfigurationOptions ConfigureDbContext(Action<DbContextOptionsBuilder> optionsAction)
{
DbContextOptionsAction = optionsAction;
return this;
}
}
}

View File

@ -6,4 +6,14 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.5.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReC.Domain\ReC.Domain.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using ReC.Domain.Entities;
namespace ReC.Infrastructure;
public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(options)
{
public DbSet<EndpointParam> EndpointParams { get; set; }
public DbSet<RecAction> Actions { get; set; }
public DbSet<OutRes> OutRes { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<RecAction>().HasNoKey();
}
}