solinject  1.0.0
C++17 Dependency Injection header-only library
ScopedServiceBuilder.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
25 
26 namespace sol::di::impl
27 {
32  template<class TService, class...TServiceParents>
34  {
35  static_assert(
36  std::conjunction_v<std::is_base_of<TServiceParents, TService>...>,
37  "The TServiceParents types must be derived from the TService type"
38  );
39  public:
42 
44  using DIService = ScopedService<TService, TServiceParents...>;
45 
48 
50  using Factory = typename DIService::Factory;
51 
56  ScopedServiceBuilder(Factory factory) : m_Factory(factory)
57  {
58  }
59 
61  {
62  return std::make_shared<DIService>(m_Factory);
63  }
64  private:
66  Factory m_Factory;
67  };
68 }
sol::di::impl::IScopedServiceBuilder::DIServicePtr
std::shared_ptr< IService > DIServicePtr
Pointer to an IService instance.
Definition: IScopedServiceBuilder.hpp:33
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
sol::di::impl::ScopedServiceBuilder::Factory
typename DIService::Factory Factory
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a...
Definition: ScopedServiceBuilder.hpp:50
sol::di::impl::ScopedServiceBuilder::ScopedServiceBuilder
ScopedServiceBuilder(Factory factory)
Constructor.
Definition: ScopedServiceBuilder.hpp:56
sol::di::impl::ScopedService
Scoped DI service.
Definition: ScopedService.hpp:33
sol::di::impl::IScopedServiceBuilder
Type-erased interface for DI service builders.
Definition: IScopedServiceBuilder.hpp:29
sol::di::impl::ScopedServiceBuilder::AbstractDIServicePtr
typename Base::DIServicePtr AbstractDIServicePtr
Pointer to an IService instance.
Definition: ScopedServiceBuilder.hpp:47
IScopedServiceBuilder.hpp
sol::di::impl::ScopedServiceBuilder
Builder for scoped DI services.
Definition: ScopedServiceBuilder.hpp:33
std::is_base_of
sol::di::impl::ScopedServiceBuilder::BuildDIService
AbstractDIServicePtr BuildDIService() const override
Builds a DI service instance.
Definition: ScopedServiceBuilder.hpp:60