Documentation
¶
Index ¶
- type ApplicationLifetime
- func (l *ApplicationLifetime) ApplicationStarted() <-chan struct{}
- func (l *ApplicationLifetime) ApplicationStopped() <-chan struct{}
- func (l *ApplicationLifetime) ApplicationStopping() <-chan struct{}
- func (l *ApplicationLifetime) NotifyStarted()
- func (l *ApplicationLifetime) NotifyStarting()
- func (l *ApplicationLifetime) NotifyStopped()
- func (l *ApplicationLifetime) NotifyStopping()
- func (l *ApplicationLifetime) StopApplication()
- type BackgroundService
- func (s *BackgroundService) ExecuteAsync(ctx context.Context) error
- func (s *BackgroundService) SetExecuteFunc(fn func(context.Context) error)
- func (s *BackgroundService) StartAsync(ctx context.Context) error
- func (s *BackgroundService) StopAsync(ctx context.Context) error
- func (s *BackgroundService) StoppingToken() <-chan struct{}
- type Environment
- type Host
- type HostBuilder
- func (b *HostBuilder) Build() IHost
- func (b *HostBuilder) ConfigureAppConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
- func (b *HostBuilder) ConfigureHostConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
- func (b *HostBuilder) ConfigureServices(configure func(services di.IServiceCollection)) IHostBuilder
- type IHost
- type IHostApplicationLifetime
- type IHostBuilder
- type IHostEnvironment
- type IHostedService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplicationLifetime ¶
type ApplicationLifetime struct {
// contains filtered or unexported fields
}
ApplicationLifetime implements IHostApplicationLifetime.
func (*ApplicationLifetime) ApplicationStarted ¶
func (l *ApplicationLifetime) ApplicationStarted() <-chan struct{}
func (*ApplicationLifetime) ApplicationStopped ¶
func (l *ApplicationLifetime) ApplicationStopped() <-chan struct{}
func (*ApplicationLifetime) ApplicationStopping ¶
func (l *ApplicationLifetime) ApplicationStopping() <-chan struct{}
func (*ApplicationLifetime) NotifyStarted ¶
func (l *ApplicationLifetime) NotifyStarted()
func (*ApplicationLifetime) NotifyStarting ¶
func (l *ApplicationLifetime) NotifyStarting()
func (*ApplicationLifetime) NotifyStopped ¶
func (l *ApplicationLifetime) NotifyStopped()
func (*ApplicationLifetime) NotifyStopping ¶
func (l *ApplicationLifetime) NotifyStopping()
func (*ApplicationLifetime) StopApplication ¶
func (l *ApplicationLifetime) StopApplication()
type BackgroundService ¶
type BackgroundService struct {
// contains filtered or unexported fields
}
BackgroundService is a base class for implementing a long running IHostedService.
func NewBackgroundService ¶
func NewBackgroundService() *BackgroundService
NewBackgroundService creates a new BackgroundService.
func (*BackgroundService) ExecuteAsync ¶
func (s *BackgroundService) ExecuteAsync(ctx context.Context) error
ExecuteAsync is the method that derived types should override to provide their execution logic. This is a helper method that can be called by derived types.
func (*BackgroundService) SetExecuteFunc ¶
func (s *BackgroundService) SetExecuteFunc(fn func(context.Context) error)
SetExecuteFunc sets the execution function for the background service. This is used by derived types to provide their execution logic.
func (*BackgroundService) StartAsync ¶
func (s *BackgroundService) StartAsync(ctx context.Context) error
StartAsync starts the background service.
func (*BackgroundService) StopAsync ¶
func (s *BackgroundService) StopAsync(ctx context.Context) error
StopAsync stops the background service.
func (*BackgroundService) StoppingToken ¶
func (s *BackgroundService) StoppingToken() <-chan struct{}
StoppingToken returns a channel that is closed when the service should stop.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment implements IHostEnvironment.
func (*Environment) IsDevelopment ¶
func (e *Environment) IsDevelopment() bool
func (*Environment) IsProduction ¶
func (e *Environment) IsProduction() bool
func (*Environment) IsStaging ¶
func (e *Environment) IsStaging() bool
func (*Environment) Name ¶
func (e *Environment) Name() string
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is the default implementation of IHost.
func NewHost ¶
func NewHost(services di.IServiceProvider, environment *Environment, lifetime IHostApplicationLifetime, hostedServices []IHostedService) *Host
NewHost creates a new Host instance.
func NewHostWithTimeout ¶
func NewHostWithTimeout(services di.IServiceProvider, environment *Environment, lifetime IHostApplicationLifetime, hostedServices []IHostedService, shutdownTimeout time.Duration) *Host
NewHostWithTimeout creates a new Host instance with custom shutdown timeout.
func (*Host) RunWithContext ¶
RunWithContext runs the host with a custom context and blocks until shutdown.
func (*Host) Services ¶
func (h *Host) Services() di.IServiceProvider
Services returns the service provider.
type HostBuilder ¶
type HostBuilder struct {
// Public properties (exposed like .NET)
Services di.IServiceCollection
Configuration config.IConfigurationManager
Environment *Environment
// contains filtered or unexported fields
}
HostBuilder is the default implementation of IHostBuilder. Corresponds to .NET HostBuilder.
func CreateDefaultBuilder ¶
func CreateDefaultBuilder(args ...string) *HostBuilder
CreateDefaultBuilder creates a host builder with default configuration. Corresponds to .NET Host.CreateDefaultBuilder(args).
func CreateEmptyBuilder ¶
func CreateEmptyBuilder() *HostBuilder
CreateEmptyBuilder creates an empty host builder without default configuration. Corresponds to .NET new HostBuilder().
func (*HostBuilder) ConfigureAppConfiguration ¶
func (b *HostBuilder) ConfigureAppConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
ConfigureAppConfiguration adds a delegate for configuring the application configuration.
func (*HostBuilder) ConfigureHostConfiguration ¶
func (b *HostBuilder) ConfigureHostConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
ConfigureHostConfiguration adds a delegate for configuring the host configuration.
func (*HostBuilder) ConfigureServices ¶
func (b *HostBuilder) ConfigureServices(configure func(services di.IServiceCollection)) IHostBuilder
ConfigureServices adds a delegate for configuring services. This method is optional - you can also directly access builder.Services.
type IHost ¶
type IHost interface {
// Services returns the service provider.
Services() di.IServiceProvider
// Start starts the host.
Start(ctx context.Context) error
// Stop stops the host.
Stop(ctx context.Context) error
// Run runs the host and blocks until shutdown.
Run() error
// RunWithContext runs the host with a custom context and blocks until shutdown.
RunWithContext(ctx context.Context) error
}
IHost represents a configured application ready to run.
type IHostApplicationLifetime ¶
type IHostApplicationLifetime interface {
// ApplicationStarted returns a channel that is closed when the application has fully started.
ApplicationStarted() <-chan struct{}
// ApplicationStopping returns a channel that is closed when the application is stopping.
ApplicationStopping() <-chan struct{}
// ApplicationStopped returns a channel that is closed when the application has stopped.
ApplicationStopped() <-chan struct{}
// StopApplication requests the application to stop.
StopApplication()
// Internal notification methods
NotifyStarting()
NotifyStarted()
NotifyStopping()
NotifyStopped()
}
IHostApplicationLifetime provides notifications for application lifetime events.
func NewApplicationLifetime ¶
func NewApplicationLifetime() IHostApplicationLifetime
NewApplicationLifetime creates a new ApplicationLifetime.
type IHostBuilder ¶
type IHostBuilder interface {
ConfigureServices(configure func(services di.IServiceCollection)) IHostBuilder
ConfigureAppConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
ConfigureHostConfiguration(configure func(config config.IConfigurationBuilder)) IHostBuilder
Build() IHost
}
IHostBuilder provides a mechanism for configuring and creating a host.
type IHostEnvironment ¶
type IHostEnvironment interface {
Name() string
IsDevelopment() bool
IsStaging() bool
IsProduction() bool
}
IHostEnvironment provides information about the hosting environment.
type IHostedService ¶
type IHostedService interface {
// StartAsync triggered when the application host is ready to start the service.
StartAsync(ctx context.Context) error
// StopAsync triggered when the application host is performing a graceful shutdown.
StopAsync(ctx context.Context) error
}
IHostedService defines methods for objects that are managed by the host.