Skip to content

Commit

Permalink
feature: Add RegisterConstant to lazy checks (#17)
Browse files Browse the repository at this point in the history
* feature: Add locations not null

* feature: add RegisterConstant lazy checking
  • Loading branch information
glennawatson committed Jul 20, 2021
1 parent 5876c3a commit 8a9a608
Show file tree
Hide file tree
Showing 16 changed files with 791 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public interface IServiceProperty2 {{ }}
public interface IServiceProperty3 {{ }}
}}";

return TestPass(source, contract, mode);
return TestHelper.TestPass(source, contract, mode);
}

[Theory]
Expand Down Expand Up @@ -143,7 +143,7 @@ public interface IServiceProperty2 {{ }}
public interface IServiceProperty3 {{ }}
}}";

return TestPass(source, contract);
return TestHelper.TestPass(source, contract);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
Diagnostics: [
{
Id: SPLATDI007,
Title: Constructor has a lazy parameter,
Severity: Error,
WarningLevel: 0,
Location: : (19,43)-(19,51),
MessageFormat: {0} constructor has a lazy parameter {1} which is not registered with RegisterLazySingleton,
Category: Compiler
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//HintName: Splat.DI.Extensions.SourceGenerated.cs

// <auto-generated />
namespace Splat
{
/// <summary>
/// Extension methods for the Splat DI source generator.
/// </summary>
internal static partial class SplatRegistrations
{
/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void Register<TInterface, TConcrete>()
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void Register<TInterface, TConcrete>(string contract)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void RegisterLazySingleton<TInterface, TConcrete>()
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="mode">The threading mode.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(System.Threading.LazyThreadSafetyMode mode)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
/// <param name="mode">The threading mode.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract, System.Threading.LazyThreadSafetyMode mode)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void Register<T>()
{
}


/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void Register<T>(string contract)
{
}

/// <summary>
/// Registers a lazy class with its concrete class.
/// </summary>
public static void RegisterLazySingleton<T>()
{
}


/// <summary>
/// Registers a lazy class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterLazySingleton<T>(string contract)
{
}

/// <summary>
/// Proxy for the Splat SetService.
/// </summary>
public static void RegisterConstant<T>(T instance) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance);

/// <summary>
/// Proxy for the Splat SetService.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);

/// <summary>
/// Registers the registrations.
/// </summary>
public static void SetupIOC()
{
SetupIOCInternal(Splat.Locator.GetLocator());
}

/// <summary>
/// Registers the registrations.
/// </summary>
/// <param name="resolver">The resolver to register with.</param>
public static void SetupIOC(Splat.IDependencyResolver resolver)
{
SetupIOCInternal(resolver);
}


static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
}

/// <summary>
/// Makes the property get added by the DI engine.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Property)]
internal class DependencyInjectionPropertyAttribute : System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DependencyInjectionPropertyAttribute"/> class.
/// </summary>
public DependencyInjectionPropertyAttribute()
{
}
}

/// <summary>
/// Makes this the constructor used by the DI engine.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Constructor)]
internal class DependencyInjectionConstructorAttribute : System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DependencyInjectionConstructorAttribute"/> class.
/// </summary>
public DependencyInjectionConstructorAttribute()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//HintName: Splat.DI.Extensions.Registrations.SourceGenerated.cs

// <auto-generated />
namespace Splat
{
internal static partial class SplatRegistrations
{
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
{
Splat.Locator.CurrentMutable.Register(() => new global::Test.Service1(), typeof(global::Test.Service1));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
Diagnostics: [
{
Id: SPLATDI007,
Title: Constructor has a lazy parameter,
Severity: Error,
WarningLevel: 0,
Location: : (19,43)-(19,51),
MessageFormat: {0} constructor has a lazy parameter {1} which is not registered with RegisterLazySingleton,
Category: Compiler
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//HintName: Splat.DI.Extensions.SourceGenerated.cs

// <auto-generated />
namespace Splat
{
/// <summary>
/// Extension methods for the Splat DI source generator.
/// </summary>
internal static partial class SplatRegistrations
{
/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void Register<TInterface, TConcrete>()
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void Register<TInterface, TConcrete>(string contract)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void RegisterLazySingleton<TInterface, TConcrete>()
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="mode">The threading mode.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(System.Threading.LazyThreadSafetyMode mode)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
/// <param name="mode">The threading mode.</param>
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract, System.Threading.LazyThreadSafetyMode mode)
{
}

/// <summary>
/// Registers a class with its concrete class.
/// </summary>
public static void Register<T>()
{
}


/// <summary>
/// Registers a class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void Register<T>(string contract)
{
}

/// <summary>
/// Registers a lazy class with its concrete class.
/// </summary>
public static void RegisterLazySingleton<T>()
{
}


/// <summary>
/// Registers a lazy class with its concrete class.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterLazySingleton<T>(string contract)
{
}

/// <summary>
/// Proxy for the Splat SetService.
/// </summary>
public static void RegisterConstant<T>(T instance) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance);

/// <summary>
/// Proxy for the Splat SetService.
/// </summary>
/// <param name="contract">Optional contract.</param>
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);

/// <summary>
/// Registers the registrations.
/// </summary>
public static void SetupIOC()
{
SetupIOCInternal(Splat.Locator.GetLocator());
}

/// <summary>
/// Registers the registrations.
/// </summary>
/// <param name="resolver">The resolver to register with.</param>
public static void SetupIOC(Splat.IDependencyResolver resolver)
{
SetupIOCInternal(resolver);
}


static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
}

/// <summary>
/// Makes the property get added by the DI engine.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Property)]
internal class DependencyInjectionPropertyAttribute : System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DependencyInjectionPropertyAttribute"/> class.
/// </summary>
public DependencyInjectionPropertyAttribute()
{
}
}

/// <summary>
/// Makes this the constructor used by the DI engine.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Constructor)]
internal class DependencyInjectionConstructorAttribute : System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DependencyInjectionConstructorAttribute"/> class.
/// </summary>
public DependencyInjectionConstructorAttribute()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//HintName: Splat.DI.Extensions.Registrations.SourceGenerated.cs

// <auto-generated />
namespace Splat
{
internal static partial class SplatRegistrations
{
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
{
Splat.Locator.CurrentMutable.Register(() => new global::Test.Service1(), typeof(global::Test.Service1));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
Diagnostics: [
{
Id: SPLATDI007,
Title: Constructor has a lazy parameter,
Severity: Error,
WarningLevel: 0,
Location: : (19,43)-(19,51),
MessageFormat: {0} constructor has a lazy parameter {1} which is not registered with RegisterLazySingleton,
Category: Compiler
}
]
}
Loading

0 comments on commit 8a9a608

Please sign in to comment.