capydi
Loading...
Searching...
No Matches
DynamicResolver.hpp
Go to the documentation of this file.
1#ifndef CAPYDI_DYNAMIC_RESOLVER_HPP_
2#define CAPYDI_DYNAMIC_RESOLVER_HPP_
3
5
6#include <functional>
7
8namespace capy::di
9{
10
11template<typename Type>
13{
14public:
15 using ReturnType = std::expected<meta::RuntimeRef<Type>, Error>;
16
17public:
20 )
21 : resolver_ { [&context] {
22 return context
23 .container
24 .template resolve<Type>();
25 }}
26 {}
27
29 meta::wrapped_with<ResolutionContext> auto const& context,
30 tag_t tag
31 )
32 : resolver_ { [context, tag] {
33 return context
34 .container
35 .template resolve<Type>(std::tuple { TagInput {
36 tag
37 }});
38 }}
39 {}
40
41public:
43 {
44 return this->resolver_();
45 }
46
47private:
48 std::function<ReturnType()> resolver_;
49};
50
51}
52
53#endif // !CAPYDI_DYNAMIC_RESOLVER_HPP_
DynamicResolver(meta::wrapped_with< ResolutionContext > auto const &context, tag_t tag)
Definition DynamicResolver.hpp:28
std::expected< meta::RuntimeRef< Type >, Error > ReturnType
Definition DynamicResolver.hpp:15
ReturnType resolve() const
Definition DynamicResolver.hpp:42
DynamicResolver(meta::wrapped_with< ResolutionContext > auto const &context)
Definition DynamicResolver.hpp:18
Definition WrappedWIth.hpp:30
Definition Decorator.hpp:19
const char * tag_t
Definition TagInput.hpp:9
Error
Enumeration of possible errors during dependency injection resolution.
Definition Error.hpp:26
Definition TagInput.hpp:12