diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-18 11:36:35 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-09-19 11:21:44 +0300 |
commit | db9092b72fc808a3e97555fbe074ad4138d69077 (patch) | |
tree | 796a92febf971e597a86ddb659ca9d75d6994569 | |
parent | 00df7ecd83cf85333a9b0e414de5d90ba04d5a20 (diff) |
service: Simplify injection of dependencies for server server
While we already have a `service.Dependencies` type around for quite a
long time, we still pass in dependencies explicitly when constructing
the actual server. This makes it harder than necessary to make a server
require more dependencies as you will have to adjust all callsites where
the server is currently getting constructed.
Simplify the code to instead inject the `service.Dependencies` type into
the server directly. This will allow us to propagate dependencies more
readily in the future.
-rw-r--r-- | internal/gitaly/service/server/info_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/server/server.go | 8 | ||||
-rw-r--r-- | internal/gitaly/service/setup/register.go | 2 |
3 files changed, 8 insertions, 4 deletions
diff --git a/internal/gitaly/service/server/info_test.go b/internal/gitaly/service/server/info_test.go index 6d3179ebc..d265e87bd 100644 --- a/internal/gitaly/service/server/info_test.go +++ b/internal/gitaly/service/server/info_test.go @@ -71,7 +71,7 @@ func TestGitalyServerInfo(t *testing.T) { func runServer(t *testing.T, cfg config.Cfg, opts ...testserver.GitalyServerOpt) string { return testserver.RunGitalyServer(t, cfg, func(srv *grpc.Server, deps *service.Dependencies) { - gitalypb.RegisterServerServiceServer(srv, NewServer(deps.GetGitCmdFactory(), deps.GetCfg().Storages)) + gitalypb.RegisterServerServiceServer(srv, NewServer(deps)) }, opts...) } diff --git a/internal/gitaly/service/server/server.go b/internal/gitaly/service/server/server.go index b4085f703..48b1a575c 100644 --- a/internal/gitaly/service/server/server.go +++ b/internal/gitaly/service/server/server.go @@ -3,6 +3,7 @@ package server import ( "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" ) @@ -13,6 +14,9 @@ type server struct { } // NewServer creates a new instance of a grpc ServerServiceServer -func NewServer(gitCmdFactory git.CommandFactory, storages []config.Storage) gitalypb.ServerServiceServer { - return &server{gitCmdFactory: gitCmdFactory, storages: storages} +func NewServer(deps *service.Dependencies) gitalypb.ServerServiceServer { + return &server{ + gitCmdFactory: deps.GetGitCmdFactory(), + storages: deps.GetCfg().Storages, + } } diff --git a/internal/gitaly/service/setup/register.go b/internal/gitaly/service/setup/register.go index 1d015ab4f..56cc2083a 100644 --- a/internal/gitaly/service/setup/register.go +++ b/internal/gitaly/service/setup/register.go @@ -68,7 +68,7 @@ func RegisterAll(srv *grpc.Server, deps *service.Dependencies) { )) gitalypb.RegisterConflictsServiceServer(srv, conflicts.NewServer(deps)) gitalypb.RegisterRemoteServiceServer(srv, remote.NewServer(deps)) - gitalypb.RegisterServerServiceServer(srv, server.NewServer(deps.GetGitCmdFactory(), deps.GetCfg().Storages)) + gitalypb.RegisterServerServiceServer(srv, server.NewServer(deps)) gitalypb.RegisterObjectPoolServiceServer(srv, objectpool.NewServer(deps)) gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps)) gitalypb.RegisterInternalGitalyServer(srv, internalgitaly.NewServer(deps)) |