diff --git a/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/DependencyInjection/GalaxyRepositoryServiceCollectionExtensions.cs b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/DependencyInjection/GalaxyRepositoryServiceCollectionExtensions.cs index 38596c9..9bc484b 100644 --- a/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/DependencyInjection/GalaxyRepositoryServiceCollectionExtensions.cs +++ b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/DependencyInjection/GalaxyRepositoryServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using ZB.MOM.WW.GalaxyRepository.Grpc; @@ -52,6 +53,9 @@ public static class GalaxyRepositoryServiceCollectionExtensions services.AddSingleton(); services.AddHostedService(); + // Allow the hosting gateway to override with its own scoped implementation. + services.TryAddSingleton(); + return services; } diff --git a/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/IGalaxyBrowseScopeProvider.cs b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/IGalaxyBrowseScopeProvider.cs new file mode 100644 index 0000000..fab290c --- /dev/null +++ b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/IGalaxyBrowseScopeProvider.cs @@ -0,0 +1,20 @@ +using Grpc.Core; + +namespace ZB.MOM.WW.GalaxyRepository.Grpc; + +/// +/// Resolves the browse-subtree glob patterns the current caller is allowed to see. +/// Lets a hosting gateway scope results per +/// identity without the library knowing the host's authorization model. The default +/// applies no scoping (full hierarchy). +/// +public interface IGalaxyBrowseScopeProvider +{ + /// + /// Returns the allowed browse-subtree globs for the current call, or + /// /empty for no restriction (full hierarchy). + /// + /// The gRPC server call context for the current request. + /// The allowed browse-subtree globs, or for no restriction. + IReadOnlyList? ResolveBrowseSubtrees(ServerCallContext context); +} diff --git a/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/NullGalaxyBrowseScopeProvider.cs b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/NullGalaxyBrowseScopeProvider.cs new file mode 100644 index 0000000..0339909 --- /dev/null +++ b/ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/Grpc/NullGalaxyBrowseScopeProvider.cs @@ -0,0 +1,10 @@ +using Grpc.Core; + +namespace ZB.MOM.WW.GalaxyRepository.Grpc; + +/// Default that applies no scoping (full hierarchy). +public sealed class NullGalaxyBrowseScopeProvider : IGalaxyBrowseScopeProvider +{ + /// + public IReadOnlyList? ResolveBrowseSubtrees(ServerCallContext context) => null; +}