Skip to content

Commit 4ca3ae7

Browse files
authored
fix: Warn if there are multiple registrations (#5)
* fix: Warn if there are multiple registrations * Fix build props
1 parent 3152fea commit 4ca3ae7

File tree

23 files changed

+753
-2
lines changed

23 files changed

+753
-2
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<Authors>Glenn Watson</Authors>
88
<Copyright>Copyright (c) 2021 ReactiveUI Association Inc</Copyright>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
10-
<PackageProjectUrl>https://github.com/reactivemarbles/ObservableEvents</PackageProjectUrl>
1110
<PackageDescription>Generates source for Splat dependency injection registrations with constructor and property injection.</PackageDescription>
1211
<Owners>glennawatson</Owners>
1312
<PackageTags>system.reactive;splat;dependency injection</PackageTags>
13+
<PackageProjectUrl>https://github.com/reactivemarbles/Splat.DI.SourceGenerator</PackageProjectUrl>
1414
<PackageReleaseNotes>https://github.com/reactivemarbles/Splat.DI.SourceGenerator/releases</PackageReleaseNotes>
1515
<RepositoryUrl>https://github.com/reactivemarbles/Splat.DI.SourceGenerator</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
Diagnostics: [
3+
{
4+
Id: SPLATDI006,
5+
Title: Interface has been registered before,
6+
Severity: Warning,
7+
WarningLevel: 1,
8+
Location: : (11,12)-(11,76),
9+
MessageFormat: {0} has been registered in multiple places,
10+
Category: Compiler
11+
}
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//HintName: Splat.DI.Extensions.SourceGenerated.cs
2+
3+
// <auto-generated />
4+
namespace Splat
5+
{
6+
/// <summary>
7+
/// Extension methods for the Splat DI source generator.
8+
/// </summary>
9+
internal static partial class SplatRegistrations
10+
{
11+
/// <summary>
12+
/// Registers a class with its concrete class.
13+
/// </summary>
14+
public static void Register<TInterface, TConcrete>()
15+
{
16+
}
17+
18+
/// <summary>
19+
/// Registers a class with its concrete class.
20+
/// </summary>
21+
/// <param name="contract">Optional contract.</param>
22+
public static void Register<TInterface, TConcrete>(string contract)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Registers a class with its concrete class.
28+
/// </summary>
29+
public static void RegisterLazySingleton<TInterface, TConcrete>()
30+
{
31+
}
32+
33+
/// <summary>
34+
/// Registers a class with its concrete class.
35+
/// </summary>
36+
/// <param name="mode">The threading mode.</param>
37+
public static void RegisterLazySingleton<TInterface, TConcrete>(System.Threading.LazyThreadSafetyMode mode)
38+
{
39+
}
40+
41+
/// <summary>
42+
/// Registers a class with its concrete class.
43+
/// </summary>
44+
/// <param name="contract">Optional contract.</param>
45+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Registers a class with its concrete class.
51+
/// </summary>
52+
/// <param name="contract">Optional contract.</param>
53+
/// <param name="mode">The threading mode.</param>
54+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract, System.Threading.LazyThreadSafetyMode mode)
55+
{
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Makes the property get added by the DI engine.
61+
/// </summary>
62+
[System.AttributeUsage(System.AttributeTargets.Property)]
63+
internal class DependencyInjectionPropertyAttribute : System.Attribute
64+
{
65+
/// <summary>
66+
/// Initializes a new instance of the <see cref="DependencyInjectionPropertyAttribute"/> class.
67+
/// </summary>
68+
public DependencyInjectionPropertyAttribute()
69+
{
70+
}
71+
}
72+
73+
/// <summary>
74+
/// Makes this the constructor used by the DI engine.
75+
/// </summary>
76+
[System.AttributeUsage(System.AttributeTargets.Constructor)]
77+
internal class DependencyInjectionConstructorAttribute : System.Attribute
78+
{
79+
/// <summary>
80+
/// Initializes a new instance of the <see cref="DependencyInjectionConstructorAttribute"/> class.
81+
/// </summary>
82+
public DependencyInjectionConstructorAttribute()
83+
{
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//HintName: Splat.DI.Extensions.Registrations.SourceGenerated.cs
2+
namespace Splat
3+
{
4+
internal static partial class SplatRegistrations
5+
{
6+
static SplatRegistrations()
7+
{
8+
{
9+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete1());
10+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>));
11+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest));
12+
}
13+
{
14+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete2());
15+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>));
16+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest));
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
Diagnostics: [
3+
{
4+
Id: SPLATDI006,
5+
Title: Interface has been registered before,
6+
Severity: Warning,
7+
WarningLevel: 1,
8+
Location: : (11,12)-(11,83),
9+
MessageFormat: {0} has been registered in multiple places,
10+
Category: Compiler
11+
}
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//HintName: Splat.DI.Extensions.SourceGenerated.cs
2+
3+
// <auto-generated />
4+
namespace Splat
5+
{
6+
/// <summary>
7+
/// Extension methods for the Splat DI source generator.
8+
/// </summary>
9+
internal static partial class SplatRegistrations
10+
{
11+
/// <summary>
12+
/// Registers a class with its concrete class.
13+
/// </summary>
14+
public static void Register<TInterface, TConcrete>()
15+
{
16+
}
17+
18+
/// <summary>
19+
/// Registers a class with its concrete class.
20+
/// </summary>
21+
/// <param name="contract">Optional contract.</param>
22+
public static void Register<TInterface, TConcrete>(string contract)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Registers a class with its concrete class.
28+
/// </summary>
29+
public static void RegisterLazySingleton<TInterface, TConcrete>()
30+
{
31+
}
32+
33+
/// <summary>
34+
/// Registers a class with its concrete class.
35+
/// </summary>
36+
/// <param name="mode">The threading mode.</param>
37+
public static void RegisterLazySingleton<TInterface, TConcrete>(System.Threading.LazyThreadSafetyMode mode)
38+
{
39+
}
40+
41+
/// <summary>
42+
/// Registers a class with its concrete class.
43+
/// </summary>
44+
/// <param name="contract">Optional contract.</param>
45+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Registers a class with its concrete class.
51+
/// </summary>
52+
/// <param name="contract">Optional contract.</param>
53+
/// <param name="mode">The threading mode.</param>
54+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract, System.Threading.LazyThreadSafetyMode mode)
55+
{
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Makes the property get added by the DI engine.
61+
/// </summary>
62+
[System.AttributeUsage(System.AttributeTargets.Property)]
63+
internal class DependencyInjectionPropertyAttribute : System.Attribute
64+
{
65+
/// <summary>
66+
/// Initializes a new instance of the <see cref="DependencyInjectionPropertyAttribute"/> class.
67+
/// </summary>
68+
public DependencyInjectionPropertyAttribute()
69+
{
70+
}
71+
}
72+
73+
/// <summary>
74+
/// Makes this the constructor used by the DI engine.
75+
/// </summary>
76+
[System.AttributeUsage(System.AttributeTargets.Constructor)]
77+
internal class DependencyInjectionConstructorAttribute : System.Attribute
78+
{
79+
/// <summary>
80+
/// Initializes a new instance of the <see cref="DependencyInjectionConstructorAttribute"/> class.
81+
/// </summary>
82+
public DependencyInjectionConstructorAttribute()
83+
{
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//HintName: Splat.DI.Extensions.Registrations.SourceGenerated.cs
2+
namespace Splat
3+
{
4+
internal static partial class SplatRegistrations
5+
{
6+
static SplatRegistrations()
7+
{
8+
{
9+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete1());
10+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>), "Test1");
11+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest), "Test1");
12+
}
13+
{
14+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete2());
15+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>), "Test1");
16+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest), "Test1");
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
Diagnostics: [
3+
{
4+
Id: SPLATDI006,
5+
Title: Interface has been registered before,
6+
Severity: Warning,
7+
WarningLevel: 1,
8+
Location: : (11,12)-(11,83),
9+
MessageFormat: {0} has been registered in multiple places,
10+
Category: Compiler
11+
}
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//HintName: Splat.DI.Extensions.SourceGenerated.cs
2+
3+
// <auto-generated />
4+
namespace Splat
5+
{
6+
/// <summary>
7+
/// Extension methods for the Splat DI source generator.
8+
/// </summary>
9+
internal static partial class SplatRegistrations
10+
{
11+
/// <summary>
12+
/// Registers a class with its concrete class.
13+
/// </summary>
14+
public static void Register<TInterface, TConcrete>()
15+
{
16+
}
17+
18+
/// <summary>
19+
/// Registers a class with its concrete class.
20+
/// </summary>
21+
/// <param name="contract">Optional contract.</param>
22+
public static void Register<TInterface, TConcrete>(string contract)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Registers a class with its concrete class.
28+
/// </summary>
29+
public static void RegisterLazySingleton<TInterface, TConcrete>()
30+
{
31+
}
32+
33+
/// <summary>
34+
/// Registers a class with its concrete class.
35+
/// </summary>
36+
/// <param name="mode">The threading mode.</param>
37+
public static void RegisterLazySingleton<TInterface, TConcrete>(System.Threading.LazyThreadSafetyMode mode)
38+
{
39+
}
40+
41+
/// <summary>
42+
/// Registers a class with its concrete class.
43+
/// </summary>
44+
/// <param name="contract">Optional contract.</param>
45+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Registers a class with its concrete class.
51+
/// </summary>
52+
/// <param name="contract">Optional contract.</param>
53+
/// <param name="mode">The threading mode.</param>
54+
public static void RegisterLazySingleton<TInterface, TConcrete>(string contract, System.Threading.LazyThreadSafetyMode mode)
55+
{
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Makes the property get added by the DI engine.
61+
/// </summary>
62+
[System.AttributeUsage(System.AttributeTargets.Property)]
63+
internal class DependencyInjectionPropertyAttribute : System.Attribute
64+
{
65+
/// <summary>
66+
/// Initializes a new instance of the <see cref="DependencyInjectionPropertyAttribute"/> class.
67+
/// </summary>
68+
public DependencyInjectionPropertyAttribute()
69+
{
70+
}
71+
}
72+
73+
/// <summary>
74+
/// Makes this the constructor used by the DI engine.
75+
/// </summary>
76+
[System.AttributeUsage(System.AttributeTargets.Constructor)]
77+
internal class DependencyInjectionConstructorAttribute : System.Attribute
78+
{
79+
/// <summary>
80+
/// Initializes a new instance of the <see cref="DependencyInjectionConstructorAttribute"/> class.
81+
/// </summary>
82+
public DependencyInjectionConstructorAttribute()
83+
{
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//HintName: Splat.DI.Extensions.Registrations.SourceGenerated.cs
2+
namespace Splat
3+
{
4+
internal static partial class SplatRegistrations
5+
{
6+
static SplatRegistrations()
7+
{
8+
{
9+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete1());
10+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>), "Test2");
11+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest), "Test2");
12+
}
13+
{
14+
global::System.Lazy<Test.ITest> lazy = new global::System.Lazy<Test.ITest>(() => new global::Test.TestConcrete2());
15+
Splat.Locator.CurrentMutable.Register(() => lazy, typeof(global::System.Lazy<Test.ITest>), "Test2");
16+
Splat.Locator.CurrentMutable.Register(() => lazy.Value, typeof(global::Test.ITest), "Test2");
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)