@@ -709,6 +709,66 @@ public sealed class Item : Identifiable<long>
709709using JsonApiDotNetCore.Controllers;
710710using JsonApiDotNetCore.Services;
711711
712+ public sealed partial class ItemsController : JsonApiController<Item, long>
713+ {
714+ public ItemsController(IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory,
715+ IResourceService<Item, long> resourceService)
716+ : base(options, resourceGraph, loggerFactory, resourceService)
717+ {
718+ }
719+ }
720+ " ) ;
721+ }
722+
723+ [ Fact ]
724+ public void Can_generate_for_shared_namespace ( )
725+ {
726+ // Arrange
727+ GeneratorDriver driver = CSharpGeneratorDriver . Create ( new ControllerSourceGenerator ( ) ) ;
728+
729+ // @formatter:wrap_chained_method_calls chop_always
730+ // @formatter:keep_existing_linebreaks true
731+
732+ string source = new SourceCodeBuilder ( )
733+ . WithNamespaceImportFor ( typeof ( IIdentifiable ) )
734+ . WithNamespaceImportFor ( typeof ( ResourceAttribute ) )
735+ . InNamespace ( "ExampleApi" )
736+ . WithCode ( @"
737+ [Resource(ControllerNamespace = ""ExampleApi"")]
738+ public sealed class Item : Identifiable<long>
739+ {
740+ [Attr]
741+ public int Value { get; set; }
742+ }" )
743+ . Build ( ) ;
744+
745+ Compilation inputCompilation = new CompilationBuilder ( )
746+ . WithDefaultReferences ( )
747+ . WithSourceCode ( source )
748+ . Build ( ) ;
749+
750+ // @formatter:keep_existing_linebreaks restore
751+ // @formatter:wrap_chained_method_calls restore
752+
753+ // Act
754+ driver = driver . RunGeneratorsAndUpdateCompilation ( inputCompilation , out Compilation outputCompilation , out _ ) ;
755+
756+ // Assert
757+ inputCompilation . GetDiagnostics ( ) . Should ( ) . BeEmpty ( ) ;
758+ outputCompilation . GetDiagnostics ( ) . Should ( ) . BeEmpty ( ) ;
759+
760+ GeneratorDriverRunResult runResult = driver . GetRunResult ( ) ;
761+ runResult . Should ( ) . NotHaveDiagnostics ( ) ;
762+
763+ runResult . Should ( ) . HaveProducedSourceCode ( @"// <auto-generated />
764+
765+ using Microsoft.Extensions.Logging;
766+ using JsonApiDotNetCore.Configuration;
767+ using JsonApiDotNetCore.Controllers;
768+ using JsonApiDotNetCore.Services;
769+
770+ namespace ExampleApi;
771+
712772public sealed partial class ItemsController : JsonApiController<Item, long>
713773{
714774 public ItemsController(IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory,
0 commit comments