capydi
Loading...
Searching...
No Matches
ActionArgMatcher.hpp
Go to the documentation of this file.
1#ifndef CAPYDI_ACTION_ARG_MATCHER_HPP_
2#define CAPYDI_ACTION_ARG_MATCHER_HPP_
3
4#include "DynamicResolver.hpp"
6
8#include <tuple>
9
10namespace capy::di
11{
12
13template<typename ActionArg>
15
16template<typename Type>
17struct ActionArgMatcher<Type&>
18{
19 static std::expected<meta::RuntimeRef<Type>, Error> prepare_arg(
21 std::optional<tag_t> tag
22 ) {
23 if (tag.has_value())
24 {
25 auto resolution = context
26 .container
27 .template resolve<Type>(std::tuple { TagInput {
28 tag.value()
29 }});
30
31 return resolution;
32 }
33 else
34 {
35 auto resolution = context
36 .container
37 .template resolve<Type>();
38
39 return resolution;
40 }
41 }
42};
43
44template<typename Type>
46{
47 static std::expected<DynamicResolver<Type>, Error> prepare_arg(
49 std::optional<tag_t> tag
50 ) {
51
52 if (tag.has_value())
53 {
54 return DynamicResolver<Type> {
55 context,
56 tag.value()
57 };
58 }
59 else
60 {
61 return DynamicResolver<Type> {
62 context,
63 };
64 }
65 }
66};
67
68}
69
70#endif // !CAPYDI_ACTION_ARG_MATCHER_HPP_
Definition DynamicResolver.hpp:13
Definition WrappedWIth.hpp:30
Definition Decorator.hpp:19
Error
Enumeration of possible errors during dependency injection resolution.
Definition Error.hpp:26
static std::expected< DynamicResolver< Type >, Error > prepare_arg(meta::wrapped_with< ResolutionContext > auto &context, std::optional< tag_t > tag)
Definition ActionArgMatcher.hpp:47
static std::expected< meta::RuntimeRef< Type >, Error > prepare_arg(meta::wrapped_with< ResolutionContext > auto &context, std::optional< tag_t > tag)
Definition ActionArgMatcher.hpp:19
Definition ActionArgMatcher.hpp:14
Definition TagInput.hpp:12