Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
guibranco committed Jul 20, 2024
1 parent 17dd990 commit 49e696b
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions Src/CrispyWaffle/Composition/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Deep Source Coverage report

private static readonly Destructor _finalise = new();
#pragma warning restore S1144 // Unused private types or members should be removed

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 49e696b

Please sign in to comment.