Skip to content

Commit 6edbb58

Browse files
authored
feature: Add ability to specify your own locator (#10)
1 parent 39fa0f9 commit 6edbb58

File tree

202 files changed

+1485
-972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+1485
-972
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ There are two methods.
5252
SplatRegistrations.RegisterLazySingleton<IMessagesSqlDataSource, MessagesSqlDataSource>();
5353
```
5454

55+
You must call either `SplatRegistrations.SetupIOC()` or with the specialisation `SplatRegistrations.SetupIOC(resolver)` once during your application start. This must be done in each assembly where you use SplatRegistrations.
56+
57+
The resolver version of `SetupIOC` is used mainly for unit tests.
58+
5559
### Constructor Injection
5660
If there are more than one constructor use the `[DependencyInjectionConstructor]` attribute to signify which one should be used.
5761

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=.01.verified.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Splat
88
/// </summary>
99
internal static partial class SplatRegistrations
1010
{
11-
static SplatRegistrations()
12-
{
13-
SetupIOCInternal();
14-
}
15-
1611
/// <summary>
1712
/// Registers a class with its concrete class.
1813
/// </summary>
@@ -104,14 +99,24 @@ public static void RegisterLazySingleton<T>(string contract)
10499
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);
105100

106101
/// <summary>
107-
/// Runs the source generated code.
102+
/// Registers the registrations.
108103
/// </summary>
109104
public static void SetupIOC()
110105
{
111-
SetupIOCInternal();
106+
SetupIOCInternal(Splat.Locator.GetLocator());
112107
}
113108

114-
static partial void SetupIOCInternal();
109+
/// <summary>
110+
/// Registers the registrations.
111+
/// </summary>
112+
/// <param name="resolver">The resolver to register with.</param>
113+
public static void SetupIOC(Splat.IDependencyResolver resolver)
114+
{
115+
SetupIOCInternal(resolver);
116+
}
117+
118+
119+
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
115120
}
116121

117122
/// <summary>

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=.02.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Splat
55
{
66
internal static partial class SplatRegistrations
77
{
8-
static partial void SetupIOCInternal()
8+
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
99
{
1010
}
1111
}

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=Test1.01.verified.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Splat
88
/// </summary>
99
internal static partial class SplatRegistrations
1010
{
11-
static SplatRegistrations()
12-
{
13-
SetupIOCInternal();
14-
}
15-
1611
/// <summary>
1712
/// Registers a class with its concrete class.
1813
/// </summary>
@@ -104,14 +99,24 @@ public static void RegisterLazySingleton<T>(string contract)
10499
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);
105100

106101
/// <summary>
107-
/// Runs the source generated code.
102+
/// Registers the registrations.
108103
/// </summary>
109104
public static void SetupIOC()
110105
{
111-
SetupIOCInternal();
106+
SetupIOCInternal(Splat.Locator.GetLocator());
112107
}
113108

114-
static partial void SetupIOCInternal();
109+
/// <summary>
110+
/// Registers the registrations.
111+
/// </summary>
112+
/// <param name="resolver">The resolver to register with.</param>
113+
public static void SetupIOC(Splat.IDependencyResolver resolver)
114+
{
115+
SetupIOCInternal(resolver);
116+
}
117+
118+
119+
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
115120
}
116121

117122
/// <summary>

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=Test1.02.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Splat
55
{
66
internal static partial class SplatRegistrations
77
{
8-
static partial void SetupIOCInternal()
8+
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
99
{
1010
}
1111
}

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=Test2.01.verified.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Splat
88
/// </summary>
99
internal static partial class SplatRegistrations
1010
{
11-
static SplatRegistrations()
12-
{
13-
SetupIOCInternal();
14-
}
15-
1611
/// <summary>
1712
/// Registers a class with its concrete class.
1813
/// </summary>
@@ -104,14 +99,24 @@ public static void RegisterLazySingleton<T>(string contract)
10499
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);
105100

106101
/// <summary>
107-
/// Runs the source generated code.
102+
/// Registers the registrations.
108103
/// </summary>
109104
public static void SetupIOC()
110105
{
111-
SetupIOCInternal();
106+
SetupIOCInternal(Splat.Locator.GetLocator());
112107
}
113108

114-
static partial void SetupIOCInternal();
109+
/// <summary>
110+
/// Registers the registrations.
111+
/// </summary>
112+
/// <param name="resolver">The resolver to register with.</param>
113+
public static void SetupIOC(Splat.IDependencyResolver resolver)
114+
{
115+
SetupIOCInternal(resolver);
116+
}
117+
118+
119+
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
115120
}
116121

117122
/// <summary>

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.CircularDependencyFail_contractParameter=Test2.02.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Splat
55
{
66
internal static partial class SplatRegistrations
77
{
8-
static partial void SetupIOCInternal()
8+
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
99
{
1010
}
1111
}

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.ConstructionAndInternalPropertyInjectionTypeArgument_contractParameter=.00.verified.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Splat
88
/// </summary>
99
internal static partial class SplatRegistrations
1010
{
11-
static SplatRegistrations()
12-
{
13-
SetupIOCInternal();
14-
}
15-
1611
/// <summary>
1712
/// Registers a class with its concrete class.
1813
/// </summary>
@@ -104,14 +99,24 @@ public static void RegisterLazySingleton<T>(string contract)
10499
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);
105100

106101
/// <summary>
107-
/// Runs the source generated code.
102+
/// Registers the registrations.
108103
/// </summary>
109104
public static void SetupIOC()
110105
{
111-
SetupIOCInternal();
106+
SetupIOCInternal(Splat.Locator.GetLocator());
112107
}
113108

114-
static partial void SetupIOCInternal();
109+
/// <summary>
110+
/// Registers the registrations.
111+
/// </summary>
112+
/// <param name="resolver">The resolver to register with.</param>
113+
public static void SetupIOC(Splat.IDependencyResolver resolver)
114+
{
115+
SetupIOCInternal(resolver);
116+
}
117+
118+
119+
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
115120
}
116121

117122
/// <summary>

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.ConstructionAndInternalPropertyInjectionTypeArgument_contractParameter=.01.verified.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace Splat
55
{
66
internal static partial class SplatRegistrations
77
{
8-
static partial void SetupIOCInternal()
8+
static partial void SetupIOCInternal( Splat.IDependencyResolver resolver)
99
{
1010
{
11-
global::System.Lazy<Test.TestConcrete> lazy = new global::System.Lazy<Test.TestConcrete>(() => new global::Test.TestConcrete((global::Test.IService1)Splat.Locator.Current.GetService(typeof(global::Test.IService1)), (global::Test.IService2)Splat.Locator.Current.GetService(typeof(global::Test.IService2))){ ServiceProperty=(global::Test.IServiceProperty)Splat.Locator.Current.GetService(typeof(global::Test.IServiceProperty))} );
11+
global::System.Lazy<Test.TestConcrete> lazy = new global::System.Lazy<Test.TestConcrete>(() => new global::Test.TestConcrete((global::Test.IService1)resolver.GetService(typeof(global::Test.IService1)), (global::Test.IService2)resolver.GetService(typeof(global::Test.IService2))){ ServiceProperty=(global::Test.IServiceProperty)resolver.GetService(typeof(global::Test.IServiceProperty))} );
1212
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.TestConcrete>));
1313
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.TestConcrete));
1414
}

src/Splat.DependencyInjection.SourceGenerator.Tests/RegisterLazySingletonTests.ConstructionAndInternalPropertyInjectionTypeArgument_contractParameter=Test1.00.verified.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Splat
88
/// </summary>
99
internal static partial class SplatRegistrations
1010
{
11-
static SplatRegistrations()
12-
{
13-
SetupIOCInternal();
14-
}
15-
1611
/// <summary>
1712
/// Registers a class with its concrete class.
1813
/// </summary>
@@ -104,14 +99,24 @@ public static void RegisterLazySingleton<T>(string contract)
10499
public static void RegisterConstant<T>(T instance, string contract) => Splat.Locator.CurrentMutable.RegisterConstant<T>(instance, contract);
105100

106101
/// <summary>
107-
/// Runs the source generated code.
102+
/// Registers the registrations.
108103
/// </summary>
109104
public static void SetupIOC()
110105
{
111-
SetupIOCInternal();
106+
SetupIOCInternal(Splat.Locator.GetLocator());
112107
}
113108

114-
static partial void SetupIOCInternal();
109+
/// <summary>
110+
/// Registers the registrations.
111+
/// </summary>
112+
/// <param name="resolver">The resolver to register with.</param>
113+
public static void SetupIOC(Splat.IDependencyResolver resolver)
114+
{
115+
SetupIOCInternal(resolver);
116+
}
117+
118+
119+
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver);
115120
}
116121

117122
/// <summary>

0 commit comments

Comments
 (0)