From e2cc807f7079a7c95df66bc17bbdd9dc8ed2dd2f Mon Sep 17 00:00:00 2001 From: Samuele Lorefice Date: Sun, 21 Sep 2025 20:48:41 +0200 Subject: [PATCH] Documentation pass --- Syrette/ServiceContainer.cs | 18 ++++++++++++++++++ Syrette/ServiceDescriptor.cs | 21 ++++++++++++++++++++- Syrette/ServiceLifetime.cs | 9 +++++++++ Syrette/Syrette.csproj | 20 +++++++++++++++----- Syrette/Syrette.csproj.DotSettings | 2 ++ 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 Syrette/Syrette.csproj.DotSettings diff --git a/Syrette/ServiceContainer.cs b/Syrette/ServiceContainer.cs index a247a6e..eca2483 100644 --- a/Syrette/ServiceContainer.cs +++ b/Syrette/ServiceContainer.cs @@ -1,5 +1,8 @@ namespace Syrette; +/// +/// Container for managing service registrations and resolutions. +/// public class ServiceContainer { private readonly List descriptors = new(); private readonly Dictionary singletons = new(); @@ -13,6 +16,11 @@ public class ServiceContainer { descriptors.Where(d => d.ServiceType == typeof(TServices)) .Select(d => d.ImplementationType).ToList(); + /// + /// Registers a singleton service with its implementation. + /// + /// Interface the service is implementing + /// Implementation type of the service public ServiceContainer AddSingleton() where TImplementation : class, TInterface { descriptors.Add(new ServiceDescriptor { @@ -25,6 +33,11 @@ public class ServiceContainer { return this; } + /// + /// Registers a transient service with its implementation. + /// + /// Interface the service is implementing + /// Implementation type of the service public ServiceContainer AddTransient() where TImplementation : class, TInterface { descriptors.Add(new ServiceDescriptor { @@ -48,6 +61,11 @@ public class ServiceContainer { return method.Invoke(this, null)!; } + /// + /// Resolves and returns an instance of the requested service type. + /// + /// Interface type of the service being requested + /// Resolved service instance public TInterface GetService() { var descriptor = descriptors.FirstOrDefault(d => d.ServiceType == typeof(TInterface)); diff --git a/Syrette/ServiceDescriptor.cs b/Syrette/ServiceDescriptor.cs index ca6b1f1..587efb6 100644 --- a/Syrette/ServiceDescriptor.cs +++ b/Syrette/ServiceDescriptor.cs @@ -1,8 +1,27 @@ namespace Syrette; -public class ServiceDescriptor { +/// +/// Describes a service for dependency injection, including its type, implementation, lifetime, and required dependencies. +/// +public class ServiceDescriptor +{ + /// + /// Gets or sets the type of the service to be provided. + /// public required Type ServiceType { get; set; } + + /// + /// Gets or sets the concrete type that implements the service. + /// public required Type ImplementationType { get; set; } + + /// + /// Gets or sets the lifetime of the service (e.g., Singleton or Transient). + /// public required ServiceLifetime Lifetime { get; set; } + + /// + /// Gets or sets the list of types required by the implementation (dependencies). + /// public List RequiredTypes { get; set; } = new(); } \ No newline at end of file diff --git a/Syrette/ServiceLifetime.cs b/Syrette/ServiceLifetime.cs index b656b39..1902712 100644 --- a/Syrette/ServiceLifetime.cs +++ b/Syrette/ServiceLifetime.cs @@ -1,6 +1,15 @@ namespace Syrette; +/// +/// Defines the lifetime of a service in dependency injection. +/// public enum ServiceLifetime { + /// + /// Defines a singleton service, which is created once and shared throughout the application's lifetime. + /// Lifetime, + /// + /// Defines a transient service, which is created anew each time it is requested. + /// Transient } \ No newline at end of file diff --git a/Syrette/Syrette.csproj b/Syrette/Syrette.csproj index e608062..0f543d0 100644 --- a/Syrette/Syrette.csproj +++ b/Syrette/Syrette.csproj @@ -1,22 +1,32 @@  - + + + README.md + ./ + + net9.0 latest enable enable - 0.0.1-alpha + 0.0.1.1-alpha Syrette Lorefice Samuele Syrette is a minimalistic dependency injection library for C#. It aims to provide a simple and efficient way to achieve dependency injections in your applications without the overhead of larger frameworks. 2025 Lorefice Samuele https://git.r3d.codes/REDCODE/Syrette - https://git.r3d.codes/REDCODE/Syrette/src/branch/master/LICENSE + MIT + README.md https://git.r3d.codes/REDCODE/Syrette git - DI, Dependency Injection + DI Dependency Injection Samuele Lorefice + true true - + + true + bin\Release\Syrette.xml + diff --git a/Syrette/Syrette.csproj.DotSettings b/Syrette/Syrette.csproj.DotSettings new file mode 100644 index 0000000..89316e4 --- /dev/null +++ b/Syrette/Syrette.csproj.DotSettings @@ -0,0 +1,2 @@ + + Library \ No newline at end of file