Shared : Core

The Shared.Core project provides foundational building blocks shared across the entire generated solution. It contains utility classes, dependency registration helpers, validation extensions, configuration options, and a Result pattern implementation for consistent error handling.

Dependency Injection

The ServiceCollectionExtension class provides automated service registration helpers that scan assemblies and register concrete types against their interfaces in the DI container :
  • RegisterServicesByMarkerType : Registers all concrete types implementing a given marker interface, binding each type to its matching interfaces as scoped services.
  • RegisterServicesByGenericType : Registers concrete types that implement a specific generic interface definition, avoiding duplicate registrations through inherited interfaces.
  • RegisterServicesByGenericTypeAs : Similar to the above, but registers the type against a different generic interface definition than the one implemented, useful for registering implementations under a base contract.

Problem Details DTO

The ProblemDetailsDto class is a sealed DTO that represents standard RFC 7807 problem details responses. It exposes the HTTP status code, a title, a type string, and a collection of error messages, providing a consistent format for API error responses across the solution.

FluentValidation Extensions

The FluentValidation extensions provide helpers to integrate validation into the application pipeline :
  • OptionBuilderValidationExtensions : Adds a AddAndValidateOption method that binds a configuration section to an options class, registers a FluentValidation validator, and validates the options on application start using ValidateOnStart.
  • ToErrorListExtension : Converts a list of FluentValidation ValidationFailure objects into a list of Error objects, mapping each validation failure message to a validation error type.

Type Extensions

The TypeExtension class provides reflection helper methods for working with .NET types :
  • IsConcrete : Determines whether a type is a non-abstract class.
  • IsInternal : Determines whether a type is internal (not public and not nested public).
  • IsStatic : Determines whether a type is static (both abstract and sealed).
  • GetBaseTypes : Enumerates all base types in the inheritance chain using an iterator.

Localization Options

The Localization options define the application's culture configuration :
  • LocalizationOption : A sealed options class that holds the default culture and an array of supported cultures, bound from the Localization configuration section.
  • LocalizationOptionValidator : A FluentValidation validator that ensures both the default culture and the supported cultures are not empty.

Result Pattern

The Result pattern provides a consistent way to represent operation outcomes without relying on exceptions for flow control :
  • Error : A class that encapsulates an error message and its associated ErrorTypeEnum.
  • ErrorTypeEnum : An enum that categorizes errors by HTTP-like status codes (Validation 400, NotFound 404, BusinessRule 422, InternalError 500).
  • Result : A non-generic result class with Ok and Fail factory methods. It enforces invariants that a successful result cannot contain errors and a failed result must contain at least one error.
  • Result<T> : A generic result class that carries a value on success. It includes a null-check guard on the value and supports implicit conversion from a non-generic Result to propagate failures.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.