solinject  1.0.0
C++17 Dependency Injection header-only library
ConfigurationItem.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 
3 /*
4  * solinject - C++ Dependency Injection header-only library
5  * Copyright (C) 2022 SemperSolus0x3d
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
22 
23 #pragma once
24 #include <string>
25 
26 namespace sol::di
27 {
29  enum class ServiceLifetime
30  {
31  Singleton = 0, //< Singleton service lifetime
32  Transient, //< Transient service lifetime
33  Shared, //< Shared service lifetime
34  Scoped, //< Scoped service lifetime
35  None //< No lifetime. Only valid for interface-to-interface registration.
36  };
37 
40  {
41  public:
45  using Key = std::string;
46 
49  {
50  }
51 
57  std::string interfaceKey,
58  std::string implementationKey,
59  ServiceLifetime lifetime
60  ) :
61  m_InterfaceKey(interfaceKey),
62  m_ImplementationKey(implementationKey),
63  m_Lifetime(lifetime)
64  {
65  }
66 
72  ConfigurationItem(key, key, lifetime)
73  {
74  }
75 
78  m_InterfaceKey(other.m_InterfaceKey),
79  m_ImplementationKey(other.m_ImplementationKey),
80  m_Lifetime(other.m_Lifetime)
81  {
82  }
83 
87  {
88  swap(*this, other);
89  }
90 
93  {
94  swap(*this, other);
95  return *this;
96  }
97 
100  {
101  using std::swap;
102 
103  swap(a.m_InterfaceKey, b.m_InterfaceKey);
104  swap(a.m_ImplementationKey, b.m_ImplementationKey);
105  swap(a.m_Lifetime, b.m_Lifetime);
106  }
107 
110  Key InterfaceKey() const { return m_InterfaceKey; }
111 
114  Key ImplementationKey() const { return m_ImplementationKey; }
115 
118  ServiceLifetime Lifetime() const { return m_Lifetime; }
119 
120  private:
122  Key m_InterfaceKey;
123 
125  Key m_ImplementationKey;
126 
128  sol::di::ServiceLifetime m_Lifetime;
129  };
130 }
std::string
sol::di::ConfigurationItem::ConfigurationItem
ConfigurationItem()
Parameterless constructor.
Definition: ConfigurationItem.hpp:48
sol::di::ConfigurationItem::Lifetime
ServiceLifetime Lifetime() const
Lifetime property.
Definition: ConfigurationItem.hpp:118
sol::di::ConfigurationItem::operator=
ConfigurationItem & operator=(ConfigurationItem other) noexcept
Copy-assignment operator.
Definition: ConfigurationItem.hpp:92
sol::di::ConfigurationItem::ConfigurationItem
ConfigurationItem(std::string key, ServiceLifetime lifetime)
Constructor. Used when the interface key and the implementation key are identical.
Definition: ConfigurationItem.hpp:71
sol::di::ConfigurationItem::Key
std::string Key
Key, used to map classes, registered in a ContainerBuilder to the ones specified in a config file.
Definition: ConfigurationItem.hpp:45
sol::di::ConfigurationItem::InterfaceKey
Key InterfaceKey() const
Interface key property.
Definition: ConfigurationItem.hpp:110
sol::di::ConfigurationItem::ImplementationKey
Key ImplementationKey() const
Implementation key property.
Definition: ConfigurationItem.hpp:114
sol::di::ConfigurationItem
DI configuration item.
Definition: ConfigurationItem.hpp:39
std::swap
T swap(T... args)
sol::di::ServiceLifetime
ServiceLifetime
Service lifetime.
Definition: ConfigurationItem.hpp:29
sol::di::ConfigurationItem::ConfigurationItem
ConfigurationItem(const ConfigurationItem &other)
Copy constructor.
Definition: ConfigurationItem.hpp:77
sol::di::ConfigurationItem::swap
friend void swap(ConfigurationItem &a, ConfigurationItem &b)
Swaps to ConfigurationItem instances.
Definition: ConfigurationItem.hpp:99
sol::di::ConfigurationItem::ConfigurationItem
ConfigurationItem(ConfigurationItem &&other) noexcept
Move constructor.
Definition: ConfigurationItem.hpp:85
sol::di::ConfigurationItem::ConfigurationItem
ConfigurationItem(std::string interfaceKey, std::string implementationKey, ServiceLifetime lifetime)
Constructor.
Definition: ConfigurationItem.hpp:56