diff --git a/Src/CrispyWaffle/Composition/ServiceLocator.cs b/Src/CrispyWaffle/Composition/ServiceLocator.cs index 4ed7e0f1..ee3ad1bc 100644 --- a/Src/CrispyWaffle/Composition/ServiceLocator.cs +++ b/Src/CrispyWaffle/Composition/ServiceLocator.cs @@ -58,6 +58,7 @@ public static class ServiceLocator private static readonly Dictionary _notLoadedAssemblies = new(); #pragma warning disable S1144 // Unused private types or members should be removed + // ReSharper disable once UnusedMember.Local private static readonly Destructor _finalise = new(); #pragma warning restore S1144 // Unused private types or members should be removed @@ -119,20 +120,20 @@ private static void LoadMissingAssembly(AssemblyName missingAssembly) } /// - /// Registers the life styled internal. + /// Registers with lifetime. /// - /// The lifestyle. + /// The lifetime. /// The contract. /// The implementation. - private static void RegisterLifeStyledInternal( - Lifetime lifestyle, + private static void RegisterWithLifetimeInternal( + Lifetime lifetime, Type contract, Type implementation ) { _registrationsCalls.Add(contract, 0); - if (lifestyle == Lifetime.Transient) + if (lifetime == Lifetime.Transient) { RegisterTransientInternal(contract, implementation); return; @@ -173,20 +174,20 @@ private static void RegisterSingletonInternal(Type contract, Type implementation } /// - /// Registers the lifestyle creator internal. + /// Registers with lifetime creator. /// - /// The type of the contract. - /// The lifestyle. + /// The type of the t contract. + /// The lifetime. /// The instance creator. - private static void RegisterLifestyleCreatorInternal( - Lifetime lifestyle, + private static void RegisterWithLifetimeCreatorInternal( + Lifetime lifetime, Func instanceCreator ) { var contract = typeof(TContract); _registrationsCalls.Add(contract, 0); - if (lifestyle == Lifetime.Transient) + if (lifetime == Lifetime.Transient) { RegisterTransientInternal(instanceCreator, contract); return; @@ -639,30 +640,48 @@ public static void Register(TContract instance) } /// - /// Registers the specified lifestyle. + /// Registers this instance with transient lifetime. + /// + /// The type of the t implementation. + public static void Register() + { + Register(Lifetime.Transient); + } + + /// + /// Registers the specified lifetime. /// /// The type of the implementation. - /// The lifestyle. - public static void Register(Lifetime lifestyle = Lifetime.Transient) + /// The lifetime. + public static void Register(Lifetime lifetime) { var type = typeof(TImplementation); - RegisterLifeStyledInternal(lifestyle, type, type); + RegisterWithLifetimeInternal(lifetime, type, type); } /// - /// Registers the specified lifestyle. + /// Registers this instance. /// /// The type of the t contract. /// The type of the t implementation. - /// The lifestyle. - public static void Register( - Lifetime lifestyle = Lifetime.Transient - ) + public static void Register() + where TImplementation : TContract + { + Register(Lifetime.Transient); + } + + /// + /// Registers the specified lifetime. + /// + /// The type of the t contract. + /// The type of the t implementation. + /// The lifetime. + public static void Register(Lifetime lifetime) where TImplementation : TContract { var contract = typeof(TContract); var implementation = typeof(TImplementation); - RegisterLifeStyledInternal(lifestyle, contract, implementation); + RegisterWithLifetimeInternal(lifetime, contract, implementation); } /// @@ -672,13 +691,13 @@ public static void Register( /// /// The instance creator for an implementation onf . /// - /// The lifecycle lifestyle of the registration. + /// The lifecycle lifetime of the registration. public static void Register( Func instanceCreator, - Lifetime lifestyle = Lifetime.Transient + Lifetime lifetime = Lifetime.Transient ) { - RegisterLifestyleCreatorInternal(lifestyle, instanceCreator); + RegisterWithLifetimeCreatorInternal(lifetime, instanceCreator); } ///