You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ServiceLocator Locator Definido como una instancia
ServiceLocator::Default() Como singletón seguro para hilos
ServiceLocator::Value<ServiceType> Como instancia estática singletón genérica
SemanticValue<TBase> Polimorfismo sin punteros
Generator<TValue> Usando por el operador co_yield
auto operator->*(Object, MethodOrPropertyExtender) Para simular propiedades/métodos extensores 👉 Referencia C#
Ejemplo: Registrando un servicio
ServiceLocator::Default()
structIService
{
virtual std::string_view GetValue() constnoexcept = 0;
};
structService : publicIService
{
constexprService(const std::string_view Value) noexcept
: Value{ Value }
{
}
virtual std::string_view GetValue() constnoexceptoverride
{
return Value;
}
std::string_view Value;
};
// Registrar un tipo usando su clase base y derivada// Forma 1ServiceLocator::Default().Register<IService>(Service{ "Test" });
// Forma 2ServiceLocator::Default().Register<IService, Service>("Test");
// Forma 3ServiceLocator::Default().Register<IService>([] { return Service{ "Test" }; });
// Forma 4ServiceLocator::Default().InvokeFactory([]() -> SemanticValue<IService> { return Service{ "Test" }; });
// Forma 5// Usando un CustomType (Objecto Función)structServiceFactory
{
SemanticValue<IService> operator()() constnoexcept
{
return Service{ "Test" };
};
};
ServiceLocator::Default().InvokeFactory<ServiceFactory>();
// Forma 6// Usando un MethodFactory
SemanticValue<IService> ServiceMethodFactory() noexcept
{
return Service{ "Test" };
}
ServiceLocator::Default().InvokeFactory(ServiceMethodFactory);
// Forma 7// Combinando MethodFactory y TypeFactory (Objecto Función)ServiceLocator::Default().InvokeFactory<TypeFactory1, TypeFactory2, TypeFactory3, TypeFactory4, ...>(MethodFactory1, MethodFactory2, MethodFactory3, MethodFactory4, LambdaFactory1, LambdaFactory2, LambdaFactory3, ...);
ServiceLocator::Value<ServiceType>
// Registrar un tipo usando su clase base y derivada// Forma 1
ServiceLocator::Value<IService> = Service{ "Test" };
// Forma 2ServiceLocator::UseFactory([]() -> SemanticValue<IService> { return Service{ "Test" }; });
// Forma 3// Usando un CustomType
ServiceLocator::UseFactory<ServiceFactory>();
// Forma 4// Usando un MethodFactoryServiceLocator::UseFactory(ServiceMethodFactory);
// Forma 5// Combinando MethodFactory y TypeFactory (Objecto Función)
ServiceLocator::UseFactory<TypeFactory1, TypeFactory2, TypeFactory3, TypeFactory4, ...>(MethodFactory1, MethodFactory2, MethodFactory3, MethodFactory4, LambdaFactory1, LambdaFactory2, LambdaFactory3, ...);