@@ -41,6 +41,49 @@ public void Run() {
4141 await Assert . That ( RoslynHelpers . IsRegisterInvocation ( invocations [ 1 ] , CancellationToken . None ) ) . IsTrue ( ) ; // Matches name "Register"
4242 }
4343
44+ /// <summary>
45+ /// Verifies that the generator recognizes registrations imported with a static using directive.
46+ /// </summary>
47+ /// <returns>A task representing the asynchronous test operation.</returns>
48+ [ Test ]
49+ public async Task Generator_RecognizesStaticImportedRegistrations ( )
50+ {
51+ var source = """
52+ using static Splat.SplatRegistrations;
53+
54+ namespace Test
55+ {
56+ public static class DIRegister
57+ {
58+ static DIRegister()
59+ {
60+ Register<IService, Service>();
61+ RegisterLazySingleton<ILazyService, LazyService>();
62+ }
63+ }
64+
65+ public interface IService { }
66+ public class Service : IService { }
67+ public interface ILazyService { }
68+ public class LazyService : ILazyService { }
69+ }
70+ """ ;
71+
72+ var compilation = TestHelper . CreateCompilation ( source ) ;
73+ GeneratorDriver driver = CSharpGeneratorDriver . Create (
74+ generators : new [ ] { new Generator ( ) . AsSourceGenerator ( ) } ) ;
75+ driver = driver . RunGeneratorsAndUpdateCompilation ( compilation , out _ , out _ ) ;
76+
77+ var generated = driver . GetRunResult ( ) . Results
78+ . SelectMany ( result => result . GeneratedSources )
79+ . Single ( result => result . HintName == Constants . RegistrationFileName )
80+ . SourceText
81+ . ToString ( ) ;
82+
83+ await Assert . That ( generated ) . Contains ( "resolver.Register<global::Test.IService>" ) ;
84+ await Assert . That ( generated ) . Contains ( "global::System.Lazy<global::Test.ILazyService>" ) ;
85+ }
86+
4487 /// <summary>
4588 /// Verifies IsRegisterInvocation returns false for non-invocation nodes.
4689 /// </summary>
@@ -1239,4 +1282,4 @@ public void Run() {
12391282 var result = RoslynHelpers . ExtractContractParameter ( registerMethod , invocation , semanticModel , CancellationToken . None ) ;
12401283 await Assert . That ( result ) . IsNull ( ) ;
12411284 }
1242- }
1285+ }
0 commit comments