diff --git a/Syrette/ServiceContainer.cs b/Syrette/ServiceContainer.cs
index f499d6d..8115381 100644
--- a/Syrette/ServiceContainer.cs
+++ b/Syrette/ServiceContainer.cs
@@ -24,14 +24,29 @@ public class ServiceContainer {
/// Interface the service is implementing
/// Implementation type of the service
public ServiceContainer AddSingleton()
+ where TInterface : class
where TImplementation : class, TInterface {
- descriptors.Add(new ServiceDescriptor {
+ descriptors.Add(new () {
ServiceType = typeof(TInterface),
ImplementationType = typeof(TImplementation),
Lifetime = ServiceLifetime.Lifetime
});
return this;
}
+
+ ///
+ /// Registers a singleton service where the service type is the same as the implementation type.
+ ///
+ /// Class type of the service
+ public ServiceContainer AddSingleton()
+ where TClass : class {
+ descriptors.Add(new () {
+ ServiceType = typeof(TClass),
+ ImplementationType = typeof(TClass),
+ Lifetime = ServiceLifetime.Lifetime
+ });
+ return this;
+ }
///
/// Registers a transient service with its implementation.
@@ -39,8 +54,9 @@ public class ServiceContainer {
/// Interface the service is implementing
/// Implementation type of the service
public ServiceContainer AddTransient()
+ where TInterface : class
where TImplementation : class, TInterface {
- descriptors.Add(new ServiceDescriptor {
+ descriptors.Add(new () {
ServiceType = typeof(TInterface),
ImplementationType = typeof(TImplementation),
Lifetime = ServiceLifetime.Transient
@@ -48,6 +64,20 @@ public class ServiceContainer {
return this;
}
+ ///
+ /// Registers a transient service where the service type is the same as the implementation type.
+ ///
+ /// Class type of the service
+ public ServiceContainer AddTransient()
+ where TClass : class {
+ descriptors.Add(new () {
+ ServiceType = typeof(TClass),
+ ImplementationType = typeof(TClass),
+ Lifetime = ServiceLifetime.Transient
+ });
+ return this;
+ }
+
// you can't call generic methods with an unknown type at compile time
// so we use reflection to call the generic GetService method with the provided type
// Basically we build the method GetService() at runtime and then call it.
diff --git a/Syrette/Syrette.csproj b/Syrette/Syrette.csproj
index 6942ad6..3923285 100644
--- a/Syrette/Syrette.csproj
+++ b/Syrette/Syrette.csproj
@@ -9,7 +9,7 @@
latest
enable
enable
- 0.0.1.3-alpha
+ 0.0.1.4-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.