namespace DigitalData.UserManager.API;

public class LazyServiceProvider : IServiceProvider
{
    private Lazy<IServiceProvider>? _serviceProvider;

    public Func<IServiceProvider> Factory
    {
        set => _serviceProvider = new(value);
    }

    public object? GetService(Type serviceType)
    {
        if (_serviceProvider is null)
            throw new InvalidOperationException("GetService cannot be called before _serviceProvider is set.");
        return _serviceProvider.Value.GetService(serviceType);
    }
}
