Documentation
¶
Overview ¶
Package container provides dependency injection capabilities for the application.
Index ¶
- Constants
- func RegisterServices(container Container, cfg config.Config, app core.App) error
- func ResolveAuthService(container Container) (services.AuthService, error)
- func ResolveCommentService(container Container) (services.CommentService, error)
- func ResolveHealthService(container Container) (services.HealthServiceInterface, error)
- func ResolveProjectService(container Container) (services.ProjectService, error)
- func ResolveTaskService(container Container) (services.TaskService, error)
- func ResolveUserService(container Container) (services.UserService, error)
- func SetupGlobalContainer(cfg config.Config, app core.App) error
- type Container
- type DIContainer
- func (c *DIContainer) Has(name string) bool
- func (c *DIContainer) Register(name string, factory Factory) error
- func (c *DIContainer) RegisterSingleton(name string, factory Factory) error
- func (c *DIContainer) RegisterSingletonType(serviceType reflect.Type, factory Factory) error
- func (c *DIContainer) RegisterType(serviceType reflect.Type, factory Factory) error
- func (c *DIContainer) Resolve(name string) (interface{}, error)
- func (c *DIContainer) ResolveType(t reflect.Type) (interface{}, error)
- func (c *DIContainer) ResolveTypeWithContext(ctx context.Context, t reflect.Type) (interface{}, error)
- func (c *DIContainer) ResolveWithContext(ctx context.Context, name string) (interface{}, error)
- type DependencyError
- type Factory
- type ServiceLocator
- func (sl *ServiceLocator) GetContainer() Container
- func (sl *ServiceLocator) Has(name string) bool
- func (sl *ServiceLocator) MustResolve(name string) interface{}
- func (sl *ServiceLocator) MustResolveWithContext(ctx context.Context, name string) interface{}
- func (sl *ServiceLocator) Register(name string, factory Factory) error
- func (sl *ServiceLocator) RegisterSingleton(name string, factory Factory) error
- func (sl *ServiceLocator) Resolve(name string) (interface{}, error)
- func (sl *ServiceLocator) ResolveWithContext(ctx context.Context, name string) (interface{}, error)
- func (sl *ServiceLocator) SetContainer(container Container)
- type ServiceRegistration
Constants ¶
const ( ConfigService = "config" UserRepositoryService = "user_repository" ProjectRepositoryService = "project_repository" TaskRepositoryService = "task_repository" CommentRepositoryService = "comment_repository" TokenBlacklistRepositoryService = "token_blacklist_repository" PasswordResetTokenRepositoryService = "password_reset_token_repository" // GitHub repositories GitHubIntegrationRepositoryService = "github_integration_repository" GitHubOAuthStateRepositoryService = "github_oauth_state_repository" GitHubAuthSessionRepositoryService = "github_auth_session_repository" GitHubIssueMappingRepositoryService = "github_issue_mapping_repository" GitHubCommitLinkRepositoryService = "github_commit_link_repository" GitHubPRMappingRepositoryService = "github_pr_mapping_repository" GitHubWebhookEventRepositoryService = "github_webhook_event_repository" // Services AuthService = "auth_service" UserService = "user_service" ProjectService = "project_service" TaskService = "task_service" CommentService = "comment_service" HealthService = "health_service" // GitHub services GitHubOAuthService = "github_oauth_service" GitHubService = "github_service" GitHubWebhookService = "github_webhook_service" )
ServiceNames contains constants for service names used in DI container
Variables ¶
This section is empty.
Functions ¶
func RegisterServices ¶
RegisterServices registers all application services with the DI container
func ResolveAuthService ¶
func ResolveAuthService(container Container) (services.AuthService, error)
ResolveAuthService resolves the auth service from the container
func ResolveCommentService ¶
func ResolveCommentService(container Container) (services.CommentService, error)
ResolveCommentService resolves the comment service from the container
func ResolveHealthService ¶
func ResolveHealthService(container Container) (services.HealthServiceInterface, error)
ResolveHealthService resolves the health service from the container
func ResolveProjectService ¶
func ResolveProjectService(container Container) (services.ProjectService, error)
ResolveProjectService resolves the project service from the container
func ResolveTaskService ¶
func ResolveTaskService(container Container) (services.TaskService, error)
ResolveTaskService resolves the task service from the container
func ResolveUserService ¶
func ResolveUserService(container Container) (services.UserService, error)
ResolveUserService resolves the user service from the container
Types ¶
type Container ¶
type Container interface {
Register(name string, factory Factory) error
RegisterSingleton(name string, factory Factory) error
Resolve(name string) (interface{}, error)
ResolveWithContext(ctx context.Context, name string) (interface{}, error)
Has(name string) bool
}
Container represents a dependency injection container.
func GetServiceLocatorContainer ¶
func GetServiceLocatorContainer() Container
GetServiceLocatorContainer returns a container from the global service locator
type DIContainer ¶
type DIContainer struct {
// contains filtered or unexported fields
}
DIContainer is the default implementation of Container.
func NewContainer ¶
func NewContainer() *DIContainer
NewContainer creates a new dependency injection container.
func (*DIContainer) Has ¶
func (c *DIContainer) Has(name string) bool
Has checks if a service is registered.
func (*DIContainer) Register ¶
func (c *DIContainer) Register(name string, factory Factory) error
Register registers a factory for a named service.
func (*DIContainer) RegisterSingleton ¶
func (c *DIContainer) RegisterSingleton(name string, factory Factory) error
RegisterSingleton registers a singleton factory for a named service.
func (*DIContainer) RegisterSingletonType ¶
func (c *DIContainer) RegisterSingletonType(serviceType reflect.Type, factory Factory) error
RegisterSingletonType registers a singleton factory for a service by type.
func (*DIContainer) RegisterType ¶
func (c *DIContainer) RegisterType(serviceType reflect.Type, factory Factory) error
RegisterType registers a factory for a service by type.
func (*DIContainer) Resolve ¶
func (c *DIContainer) Resolve(name string) (interface{}, error)
Resolve resolves a dependency by name.
func (*DIContainer) ResolveType ¶
func (c *DIContainer) ResolveType(t reflect.Type) (interface{}, error)
ResolveType resolves a dependency by type using reflection.
func (*DIContainer) ResolveTypeWithContext ¶
func (c *DIContainer) ResolveTypeWithContext(ctx context.Context, t reflect.Type) (interface{}, error)
ResolveTypeWithContext resolves a dependency by type using reflection with context.
func (*DIContainer) ResolveWithContext ¶
func (c *DIContainer) ResolveWithContext(ctx context.Context, name string) (interface{}, error)
ResolveWithContext resolves a dependency by name with context.
type DependencyError ¶
DependencyError represents a dependency injection error.
func NewDependencyError ¶
func NewDependencyError(code, message string) *DependencyError
NewDependencyError creates a new dependency error
func (*DependencyError) Error ¶
func (e *DependencyError) Error() string
Error implements the error interface
type ServiceLocator ¶
type ServiceLocator struct {
// contains filtered or unexported fields
}
ServiceLocator provides a global access point to the DI container
func GetInstance ¶
func GetInstance() *ServiceLocator
GetInstance returns the singleton instance of ServiceLocator
func (*ServiceLocator) GetContainer ¶
func (sl *ServiceLocator) GetContainer() Container
GetContainer returns the underlying container
func (*ServiceLocator) Has ¶
func (sl *ServiceLocator) Has(name string) bool
Has checks if a service is registered
func (*ServiceLocator) MustResolve ¶
func (sl *ServiceLocator) MustResolve(name string) interface{}
MustResolve resolves a dependency and panics if it fails
func (*ServiceLocator) MustResolveWithContext ¶
func (sl *ServiceLocator) MustResolveWithContext(ctx context.Context, name string) interface{}
MustResolveWithContext resolves a dependency with context and panics if it fails
func (*ServiceLocator) Register ¶
func (sl *ServiceLocator) Register(name string, factory Factory) error
Register registers a factory for a named service
func (*ServiceLocator) RegisterSingleton ¶
func (sl *ServiceLocator) RegisterSingleton(name string, factory Factory) error
RegisterSingleton registers a singleton factory for a named service
func (*ServiceLocator) Resolve ¶
func (sl *ServiceLocator) Resolve(name string) (interface{}, error)
Resolve resolves a dependency by name
func (*ServiceLocator) ResolveWithContext ¶
func (sl *ServiceLocator) ResolveWithContext(ctx context.Context, name string) (interface{}, error)
ResolveWithContext resolves a dependency by name with context
func (*ServiceLocator) SetContainer ¶
func (sl *ServiceLocator) SetContainer(container Container)
SetContainer sets the underlying container
type ServiceRegistration ¶
type ServiceRegistration struct {
Factory Factory
Instance interface{}
Singleton bool
// contains filtered or unexported fields
}
ServiceRegistration represents a registered service.