14#include "arcane/utils/internal/DependencyInjection.h"
16#include "arcane/utils/UniqueArray.h"
17#include "arcane/utils/ExternalRef.h"
18#include "arcane/utils/FatalErrorException.h"
23namespace Arcane::DependencyInjection
38 : m_instance(instance)
52 for (Integer i = 0, n = m_instance_list.size(); i < n; ++i)
53 delete m_instance_list[i].m_instance;
54 m_instance_list.clear();
61 Int32 index = m_instance_list.size();
62 m_instance_list.add(InstanceInfo{ instance, index });
64 IInjectedInstance* instance(Int32 index)
const {
return m_instance_list[index].m_instance; }
65 Int32 nbInstance()
const {
return m_instance_list.size(); }
69 UniqueArray<InstanceInfo> m_instance_list;
73 UniqueArray<Ref<impl::IInstanceFactory>> m_factories;
98_add(IInjectedInstance* instance)
100 m_p->addInstance(instance);
109 return m_p->nbInstance();
115IInjectedInstance* Injector::
116_value(Integer i)
const
118 return m_p->instance(i);
127 return m_p->m_factories.size();
133impl::IInstanceFactory* Injector::
134_factory(Integer i)
const
136 return m_p->m_factories[i].get();
147namespace Arcane::DependencyInjection::impl
153void ConstructorRegistererBase::
154_doError1(
const String& message,
int nb_value)
166 : m_property(property)
167 , m_name(property.name())
201 m_p->m_factories.add(f);
208hasName(
const String& str)
const
210 return str == m_p->m_name;
217fillWithImplementationNames(Array<String>& names)
const
219 names.add(m_p->m_name);
230: m_factory_create_func(
func)
231, m_factory_property(property)
245namespace Arcane::DependencyInjection
252fillWithGlobalFactories()
257 auto func =
g->infoCreatorWithPropertyFunction();
260 fi = (*func)(
g->property());
262 m_p->m_factories.addRange(
fi->m_p->m_factories);
264 g =
g->nextRegisterer();
267 ARCANE_FATAL(
"Infinite loop in DependencyInjection global factories");
275printFactories()
const
277 std::ostringstream ostr;
279 auto f = [&](impl::IInstanceFactory* v) ->
bool {
280 const impl::ConcreteFactoryTypeInfo& cfi = v->concreteFactoryInfo();
281 ostr <<
"I=" << index <<
" " <<
typeid(v).name()
282 <<
"\n interface=" << cfi.interfaceTypeInfo().traceInfo()
283 <<
"\n concrete=" << cfi.concreteTypeInfo().traceInfo()
284 <<
"\n constructor=" << cfi.constructorTypeInfo().traceInfo()
289 FactoryVisitorFunctor ff(f);
290 _iterateFactories(String(), &ff);
291 String s = ostr.str();
307 Integer n = _nbFactory();
309 for (Integer i = 0; i < n; ++i) {
315 if (functor->execute(f))
327 IInstanceVisitorFunctor*
lambda)
330 Integer n = _nbValue();
331 for (Integer i = 0; i < n; ++i) {
346_doError(
const TraceInfo& ti,
const String& message)
355_printValidImplementationAndThrow(
const TraceInfo& ti,
356 const String& implementation_name,
357 FactoryFilterFunc filter_func)
362 UniqueArray<String> valid_names;
363 for (
Int32 i = 0, n = _nbFactory(); i < n; ++i) {
364 impl::IInstanceFactory* f = _factory(i);
365 if (filter_func(f)) {
366 f->factoryInfo()->fillWithImplementationNames(valid_names);
369 String message = String::format(
"No implementation named '{0}' found", implementation_name);
373 if (valid_names.size() == 0)
374 message2 =
" and no implementation is available.";
375 else if (valid_names.size() == 1)
376 message2 = String::format(
". Valid value is: '{0}'.", valid_names[0]);
378 message2 = String::format(
". Valid values are: '{0}'.", String::join(
", ", valid_names));
379 _doError(ti, message + message2);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name)
Macro pour définir les méthodes et types une classe qui utilise un compteur de référence.
Interface d'un fonctor pour appliqué à chaque fabrique.
Informations pour une fabrique.
GlobalRegisterer(FactoryCreateFunc func, const ProviderProperty &property) noexcept
Crée en enregistreur pour le service name et la fonction func.
Fabrique pour une instance encapsulée par une référence (i.e Ref<T>).
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Chaîne de caractères unicode.
Espace de nom de Arccore.
Int32 Integer
Type représentant un entier.