solinject  1.0.0
C++17 Dependency Injection header-only library
IServiceTyped.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 <memory>
25 #include <functional>
26 #include "IService.hpp"
27 
28 namespace sol::di::impl
29 {
31  template <class T>
32  class IServiceTyped : public virtual IService
33  {
34  public:
36  using ServicePtr = typename std::shared_ptr<T>;
37 
42  using Factory = typename std::function<ServicePtr(const Container&)>;
43 
44  virtual ~IServiceTyped() = 0;
45 
51  virtual ServicePtr GetService(const Container& container) = 0;
52  };
53 
54  template <class T>
56 }
std::shared_ptr
sol::di::Container
Dependency Injection container.
Definition: Container.hpp:48
sol::di::impl::IService
Type-erased DI service interface.
Definition: IService.hpp:31
sol::di::impl::IServiceTyped
DI service interface.
Definition: IServiceTyped.hpp:32
std::function
sol::di::impl::IServiceTyped::GetService
virtual ServicePtr GetService(const Container &container)=0
Resolves the service.
sol::di::impl::IServiceTyped< TServiceParents >::ServicePtr
typename std::shared_ptr< TServiceParents > ServicePtr
Pointer to an instance of a service.
Definition: IServiceTyped.hpp:36
sol::di::impl::IServiceTyped< TServiceParents >::Factory
typename std::function< ServicePtr(const Container &)> Factory
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a...
Definition: IServiceTyped.hpp:42
IService.hpp