dotnet-cqrs/Svrnty.CQRS/Configuration/CqrsConfiguration.cs

39 lines
1.0 KiB
C#

#nullable enable
using System;
using System.Collections.Generic;
namespace Svrnty.CQRS.Configuration;
/// <summary>
/// Configuration for CQRS services and endpoints.
/// Supports extension by third-party packages through generic configuration storage.
/// </summary>
public class CqrsConfiguration
{
private readonly Dictionary<Type, object> _configurations = new();
/// <summary>
/// Sets a configuration object for a specific type
/// </summary>
public void SetConfiguration<T>(T config) where T : class
{
_configurations[typeof(T)] = config;
}
/// <summary>
/// Gets a configuration object for a specific type
/// </summary>
public T? GetConfiguration<T>() where T : class
{
return _configurations.TryGetValue(typeof(T), out var config) ? config as T : null;
}
/// <summary>
/// Checks if a configuration exists for a specific type
/// </summary>
public bool HasConfiguration<T>() where T : class
{
return _configurations.ContainsKey(typeof(T));
}
}