solinject  1.0.0
C++17 Dependency Injection header-only library
ScopedService.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 "SingletonService.hpp"
25 
26 namespace sol::di::impl
27 {
32  template<class TService, class...TServiceParents>
33  class ScopedService :
34  public SingletonService<TService, TServiceParents...>
35  {
36  static_assert(
37  std::conjunction_v<std::is_base_of<TServiceParents, TService>...>,
38  "The TServiceParents types must be derived from the TService type"
39  );
40  public:
42  using Base = SingletonService<TService, TServiceParents...>;
43 
45  using Factory = typename Base::Factory;
46 
48  using VoidPtr = typename IService::VoidPtr;
49 
54  ScopedService(Factory factory) : Base(factory)
55  {
56  }
57  }; // class SingletonService
58 } // sol::di::impl
std::shared_ptr
sol::di::impl::ScopedService::ScopedService
ScopedService(Factory factory)
Constructor.
Definition: ScopedService.hpp:54
sol::di::impl::ScopedService::Factory
typename Base::Factory Factory
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a...
Definition: ScopedService.hpp:45
SingletonService.hpp
sol::di::impl::SingletonService
Singleton DI service.
Definition: SingletonService.hpp:34
sol::di::impl::SingletonService< TService, TServiceParents... >::Factory
typename Base::Factory Factory
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a...
Definition: SingletonService.hpp:53
sol::di::impl::ScopedService
Scoped DI service.
Definition: ScopedService.hpp:33
sol::di::impl::IService::VoidPtr
std::shared_ptr< void > VoidPtr
Pointer to void.
Definition: IService.hpp:38
std::is_base_of