@@ -92,14 +92,12 @@ private static string GenerateClass(string namespaceName, string className, Spec
9292 // Usings
9393 var usings = Array . Empty < UsingDirectiveSyntax > ( ) ;
9494
95- // Field declaration: private IRealTimeLayoutService RTLayoutService ;
95+ // Field declaration: private IRealTimeLayoutService;
9696 var fieldDeclaration = SyntaxFactory . FieldDeclaration (
9797 SyntaxFactory . VariableDeclaration (
9898 SyntaxFactory . IdentifierName ( ServiceInterfaceName ) )
99- . AddVariables ( SyntaxFactory . VariableDeclarator ( ServiceVariableName )
100- . WithInitializer ( SyntaxFactory . EqualsValueClause (
101- SyntaxFactory . ParseExpression ( $ "Ioc.Default.GetRequiredService<{ ServiceInterfaceName } >()") ) ) ) )
102- . AddModifiers ( SyntaxFactory . Token ( SyntaxKind . PrivateKeyword ) , SyntaxFactory . Token ( SyntaxKind . ReadOnlyKeyword ) )
99+ . AddVariables ( SyntaxFactory . VariableDeclarator ( ServiceVariableName ) ) )
100+ . AddModifiers ( SyntaxFactory . Token ( SyntaxKind . PrivateKeyword ) )
103101 . AddAttributeLists ( SourceGeneratorHelper . GetAttributeForField ( nameof ( RealTimeLayoutGenerator ) ) ) ;
104102
105103 // Method: InitializeContentLayout
@@ -149,6 +147,29 @@ private static IEnumerable<StatementSyntax> CreateContentLayoutBody(Specificatio
149147 {
150148 var statements = new List < StatementSyntax > ( ) ;
151149
150+ if ( isInitialize )
151+ {
152+
153+ statements . Add (
154+ SyntaxFactory . ExpressionStatement (
155+ SyntaxFactory . AssignmentExpression (
156+ SyntaxKind . SimpleAssignmentExpression ,
157+ SyntaxFactory . IdentifierName ( ServiceVariableName ) ,
158+ SyntaxFactory . InvocationExpression (
159+ SyntaxFactory . MemberAccessExpression (
160+ SyntaxKind . SimpleMemberAccessExpression ,
161+ SyntaxFactory . MemberAccessExpression (
162+ SyntaxKind . SimpleMemberAccessExpression ,
163+ SyntaxFactory . IdentifierName ( "Ioc" ) ,
164+ SyntaxFactory . IdentifierName ( "Default" ) ) ,
165+ SyntaxFactory . GenericName (
166+ SyntaxFactory . Identifier ( "GetRequiredService" ) )
167+ . WithTypeArgumentList (
168+ SyntaxFactory . TypeArgumentList (
169+ SyntaxFactory . SingletonSeparatedList < TypeSyntax > (
170+ SyntaxFactory . IdentifierName ( ServiceInterfaceName ) ) ) ) ) ) ) ) ) ;
171+ }
172+
152173 if ( type == SpecificationType . Window )
153174 {
154175 statements . Add (
0 commit comments