API Reference¶
Core Types¶
Ref¶
Ref<T> is an alias for std::shared_ptr<T>. Used to hold references to services.
MakeRef(args...)¶
Creates a Ref<T> instance. Factory function for service creation.
template <typename T, typename... TArgs>
requires(std::is_constructible_v<T, TArgs...>)
Ref<T> MakeRef(TArgs&&... args);
Lifetime¶
Enum specifying a service lifetime:
| Value | Description |
|---|---|
| Transient | New instance each request |
| Scoped | One instance per scope |
| Singleton | Single instance per application |
ServiceFactory¶
Function type for service factories:
ServiceCollection¶
Lifetime Registration Methods¶
Concrete Type Registration¶
ServiceCollection& AddSingleton<TService>();
ServiceCollection& AddScoped<TService>();
ServiceCollection& AddTransient<TService>();
Contract/Interface Registration¶
ServiceCollection& AddSingleton<TContract, TService>();
ServiceCollection& AddScoped<TContract, TService>();
ServiceCollection& AddTransient<TContract, TService>();
Factory Registration¶
ServiceCollection& AddSingleton<TService>(const ServiceFactory& factory);
ServiceCollection& AddScoped<TService>(const ServiceFactory& factory);
ServiceCollection& AddTransient<TService>(const ServiceFactory& factory);
Instance Registration¶
ServiceCollection& AddSingleton<TService>(Ref<TService> element);
ServiceCollection& AddSingleton<TContract, TService>(Ref<TService> element);
Utility Methods¶
ServiceProvider¶
Service Retrieval¶
Utility Methods¶
ServiceScope¶
Constructor¶
ServiceScope(const Ref<ServiceDefinitionMap>& serviceDefinitionMap,
const Ref<ServicesCache>& singletonsCache);
Methods¶
Logger¶
Log Levels¶
| Level | Description |
|---|---|
| Debug | Debug messages (default in debug) |
| Trace | Trace messages (default in release) |
| Information | General information messages |
| Warning | Warning messages |
| Error | Error messages |
| Fatal | Fatal errors (throws exception) |
Logging Methods¶
template <typename... TArgs>
void LogDebug(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void LogTrace(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void LogInformation(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void LogWarning(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void LogError(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void LogFatal(fmt::format_string<TArgs...> fmt, TArgs&&... args);
template <typename... TArgs>
void Assert(bool assertion, fmt::format_string<TArgs...> fmt, TArgs&&... args);
LoggerOptions¶
Configuration class for logging behavior:
Inject Ref<LoggerOptions> to customize logging level.
Application¶
IApplication¶
Abstract base class for applications:
class IApplication {
public:
IApplication(const Ref<ServiceProvider>& rootServiceProvider);
virtual ~IApplication() = default;
Ref<ServiceProvider> GetRootServiceProvider() const;
virtual void Run() = 0;
};
The IApplication singleton is automatically registered when using ApplicationBuilder.
ApplicationBuilder¶
For registering applications with the container: