-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ public static class ServiceLocator | |
private static readonly Dictionary<string, Exception> _notLoadedAssemblies = new(); | ||
|
||
#pragma warning disable S1144 // Unused private types or members should be removed | ||
// ReSharper disable once UnusedMember.Local | ||
Check warning on line 61 in Src/CrispyWaffle/Composition/ServiceLocator.cs GitHub Actions / Deep Source Coverage report
|
||
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) | |
} | ||
|
||
/// <summary> | ||
/// Registers the life styled internal. | ||
/// Registers with lifetime. | ||
/// </summary> | ||
/// <param name="lifestyle">The lifestyle.</param> | ||
/// <param name="lifetime">The lifetime.</param> | ||
/// <param name="contract">The contract.</param> | ||
/// <param name="implementation">The implementation.</param> | ||
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 | |
} | ||
|
||
/// <summary> | ||
/// Registers the lifestyle creator internal. | ||
/// Registers with lifetime creator. | ||
/// </summary> | ||
/// <typeparam name="TContract">The type of the contract.</typeparam> | ||
/// <param name="lifestyle">The lifestyle.</param> | ||
/// <typeparam name="TContract">The type of the t contract.</typeparam> | ||
/// <param name="lifetime">The lifetime.</param> | ||
/// <param name="instanceCreator">The instance creator.</param> | ||
private static void RegisterLifestyleCreatorInternal<TContract>( | ||
Lifetime lifestyle, | ||
private static void RegisterWithLifetimeCreatorInternal<TContract>( | ||
Lifetime lifetime, | ||
Func<TContract> 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>(TContract instance) | |
} | ||
|
||
/// <summary> | ||
/// Registers the specified lifestyle. | ||
/// Registers this instance with transient lifetime. | ||
/// </summary> | ||
/// <typeparam name="TImplementation">The type of the t implementation.</typeparam> | ||
public static void Register<TImplementation>() | ||
{ | ||
Register<TImplementation>(Lifetime.Transient); | ||
} | ||
|
||
/// <summary> | ||
/// Registers the specified lifetime. | ||
/// </summary> | ||
/// <typeparam name="TImplementation">The type of the implementation.</typeparam> | ||
/// <param name="lifestyle">The lifestyle.</param> | ||
public static void Register<TImplementation>(Lifetime lifestyle = Lifetime.Transient) | ||
/// <param name="lifetime">The lifetime.</param> | ||
public static void Register<TImplementation>(Lifetime lifetime) | ||
{ | ||
var type = typeof(TImplementation); | ||
RegisterLifeStyledInternal(lifestyle, type, type); | ||
RegisterWithLifetimeInternal(lifetime, type, type); | ||
} | ||
|
||
/// <summary> | ||
/// Registers the specified lifestyle. | ||
/// Registers this instance. | ||
/// </summary> | ||
/// <typeparam name="TContract">The type of the t contract.</typeparam> | ||
/// <typeparam name="TImplementation">The type of the t implementation.</typeparam> | ||
/// <param name="lifestyle">The lifestyle.</param> | ||
public static void Register<TContract, TImplementation>( | ||
Lifetime lifestyle = Lifetime.Transient | ||
) | ||
public static void Register<TContract, TImplementation>() | ||
where TImplementation : TContract | ||
{ | ||
Register<TContract, TImplementation>(Lifetime.Transient); | ||
} | ||
|
||
/// <summary> | ||
/// Registers the specified lifetime. | ||
/// </summary> | ||
/// <typeparam name="TContract">The type of the t contract.</typeparam> | ||
/// <typeparam name="TImplementation">The type of the t implementation.</typeparam> | ||
/// <param name="lifetime">The lifetime.</param> | ||
public static void Register<TContract, TImplementation>(Lifetime lifetime) | ||
where TImplementation : TContract | ||
{ | ||
var contract = typeof(TContract); | ||
var implementation = typeof(TImplementation); | ||
RegisterLifeStyledInternal(lifestyle, contract, implementation); | ||
RegisterWithLifetimeInternal(lifetime, contract, implementation); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -672,13 +691,13 @@ public static void Register<TContract, TImplementation>( | |
/// <param name="instanceCreator"> | ||
/// The instance creator for an implementation onf <typeparamref name="TContract"/>. | ||
/// </param> | ||
/// <param name="lifestyle">The lifecycle lifestyle of the registration.</param> | ||
/// <param name="lifetime">The lifecycle lifetime of the registration.</param> | ||
public static void Register<TContract>( | ||
Func<TContract> instanceCreator, | ||
Lifetime lifestyle = Lifetime.Transient | ||
Lifetime lifetime = Lifetime.Transient | ||
Check warning Code scanning / Sonarscharp (reported by Codacy) Use the overloading mechanism instead of the optional parameters. Warning
Use the overloading mechanism instead of the optional parameters.
|
||
) | ||
{ | ||
RegisterLifestyleCreatorInternal(lifestyle, instanceCreator); | ||
RegisterWithLifetimeCreatorInternal(lifetime, instanceCreator); | ||
} | ||
|
||
/// <summary> | ||
|