7#if !defined(__cpp_concepts)
8#error "This library requires concepts"
32 template <
typename T,
typename...
OTHERS>
33 constexpr inline bool is_same_as_any_v = std::disjunction_v<std::is_same<std::decay_t<OTHERS>, std::decay_t<T>>...>;
44 struct DefaultImplementationStruct {};
45 constexpr inline DefaultImplementationStruct DefaultImplementation;
52 Lifetime DefaultLifetime = Lifetime::Transient;
59 template <
typename INTERFACE>
60 bool HasAnyImplementationsOf()
const;
64 template <
typename INTERFACE>
65 std::shared_ptr<INTERFACE>
Resolve();
67 template <
typename INTERFACE>
68 std::shared_ptr<INTERFACE> ResolveByName(std::string_view name);
70 template <
typename INTERFACE>
71 std::vector<std::shared_ptr<INTERFACE>> ResolveAll();
75 template <
typename TYPE>
76 std::shared_ptr<TYPE>
Create();
78 template <
typename TYPE>
79 std::unique_ptr<TYPE> CreateRaw();
84 mParentContainer =
nullptr;
87 auto const& Containers()
const {
return mContainers; }
88 auto const& DebugStore()
const {
return mDebugStore; }
92 struct BaseInterfaceContainer
94 virtual ~BaseInterfaceContainer()
noexcept =
default;
96 Lifetime DefaultLifetime = Lifetime::Default;
99 template <
typename INTERFACE>
100 struct InterfaceContainer;
102 template <
typename INTERFACE>
103 struct ImplementationContainer;
105 template <
typename INTERFACE>
108 template <
typename INTERFACE,
typename IMPLEMENTATION>
111 std::map<std::type_index, std::unique_ptr<BaseInterfaceContainer>> mContainers;
112 std::vector<std::type_index> mResolutionStack;
113 std::vector<std::pair<std::shared_ptr<void>, std::function<
void(
Container&, std::shared_ptr<void>)>>> mCreationsToReport;
116 std::map<void const*, std::pair<std::type_index, std::weak_ptr<void>>> mDebugStore;
118 template <
typename INSTANCE>
119 void ReportCreation(std::shared_ptr<INSTANCE>
const&
obj, std::function<
void(
Container&, std::shared_ptr<void>)>
func);
121 void ReportAwaitingCreations()
123 auto creations = std::exchange(mCreationsToReport, {});
128 template <
typename INTERFACE,
typename T>
129 std::shared_ptr<INTERFACE> Instantiate(T&
factory);
constexpr auto bit_count
Equal to the number of bits in the type.
TODO: Split into ContainerBuilder and Container (or [Dependency]Registry and [Dependency]Container) O...
std::shared_ptr< TYPE > Create()
Other.
std::shared_ptr< INTERFACE > Resolve()
Resolves.
void RegisterType(ARGS &&... args)
Registers.