Skip to content

Commit d29b3c3

Browse files
authored
Merge pull request #23 from 7bitcoder/dev
Add version 3.3.0
2 parents 5ab287b + a02f34a commit d29b3c3

25 files changed

+334
-162
lines changed

.github/workflows/MacOs.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ jobs:
1919
{ tool: apple-clang },
2020
{ tool: gcc, ver: 10 },
2121
{ tool: gcc, ver: 11 },
22-
{ tool: gcc, ver: 12 },
23-
{ tool: gcc, ver: 13 } ]
22+
{ tool: gcc, ver: 12 } ]
2423
build_type: [ Release ]
2524
os: [ macos-12 ]
2625
std: [ 17 ]

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15.0)
33
set(_7BIT_DI_LIBRARY 7bitDI)
44

55
set(_7BIT_DI_VERSION_MAJOR 3)
6-
set(_7BIT_DI_VERSION_MINOR 2)
6+
set(_7BIT_DI_VERSION_MINOR 3)
77
set(_7BIT_DI_VERSION_PATCH 0)
88

99
set(_7BIT_DI_VERSION ${_7BIT_DI_VERSION_MAJOR}.${_7BIT_DI_VERSION_MINOR}.${_7BIT_DI_VERSION_PATCH})

Docs/advanced-guides.rst

-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ Advanced Guides
1111
advanced-guides/using-aliases
1212
advanced-guides/register-utility-class
1313
advanced-guides/injected-utility-class
14-
advanced-guides/configuring-service-provider
1514
advanced-guides/building-library

Docs/advanced-guides/injected-utility-class.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
Injected Utility Class
22
========================================
33

4-
Library provides also Injected_ utility class.
5-
This base class has inject() method that can be used to inject services in simple inline way, also
6-
there are InjectedSingleton, InjectedScoped and InjectedTransient base classes that are inheriting
7-
from Injected and Registered classes to combine these two features. Injected class has also method
8-
getProvider(), raw provider can be used to get keyed services for example.
4+
The library provides also Injected_ utility class.
5+
This base class has inject() method that can be used to inject services in a simple inline way, also
6+
there are InjectedSingleton, InjectedScoped and InjectedTransient base classes that inherit
7+
from Injected and Registered classes to combine these two features. The injected class has also a method
8+
getProvider(), the raw provider can be used to get keyed services for example.
99

1010
.. _Injected: ../reference/di/utils/injected.html
1111

1212
.. note::
13-
Class should inherit Injected constructor with 'using Injected::Injected;' in public section
13+
The class should inherit Injected constructor with 'using Injected::Injected;' in the public section
1414

1515
.. literalinclude:: ../../Examples/Guides/InjectedUtilityClass.cpp
1616
:caption: Examples/Guides/InjectedUtilityClass

Docs/advanced-guides/register-utility-class.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Register Utility Class
22
========================================
33

4-
Library provides simple template RegisterService_ utility class.
5-
This base class can be used to automatically register class in service collection with use of specialised TRegisterer.
4+
The library provides a simple template RegisterService_ utility class.
5+
This base class can be used to automatically register class in service collection with the use of a specialized TRegisterer.
66
There are already created aliases RegisterSingleton_, RegisterScoped_, RegisterTransient_ that are registering services
77
in GlobalServices_ singleton.
88

99
.. note::
10-
Class should inherit Injected constructor with 'using Injected::Injected;' in public section
10+
The class should inherit Injected constructor with 'using Injected::Injected;' in the public section
1111

1212
.. _RegisterService: ../reference/di/utils/register.html
1313
.. _RegisterSingleton: ../reference/di/utils/register.html

Docs/advanced-guides/using-aliases.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ Using Aliases
22
========================================
33

44
With the use of aliases, one service can be injected through its multiple base classes, also aliases can be chained.
5-
In case of injecting multiple aliases all real services will be fetched.
5+
In case of injecting multiple aliases, all real services will be fetched.
66

77
.. warning::
88
Using aliases is resource intensive, especially for injecting transient and multiple services, provider recursively
9-
traverses through aliases chain to find proper service. Mixing scoped and singleton aliases for same base type will
9+
traverses through the aliases chain to find the proper service. Mixing scoped and singleton aliases for the same base type will
1010
lead to undefined behavior
1111

1212
.. literalinclude:: ../../Examples/Guides/ServiceAliases.cpp

Docs/basic-guides.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Basic Guides
1212
basic-guides/injecting-multiple-services
1313
basic-guides/injection-rules
1414
basic-guides/injecting-service-provider
15+
basic-guides/configuring-service-provider

Docs/advanced-guides/configuring-service-provider.rst renamed to Docs/basic-guides/configuring-service-provider.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ read comment documentation for details:
1010
:caption: Include/SevenBit/DI/ServiceProviderOptions.hpp
1111
:language: C++
1212

13-
Pass the custom options to the ServiceCollection buildServiceProvider method to change produced
14-
service provider behaviour
13+
Pass the custom options to the ServiceCollection buildServiceProvider method to change the produced
14+
service provider behavior
1515

1616
.. literalinclude:: ../../Examples/Guides/ConfiguredServiceProvider.cpp
1717
:caption: Examples/Guides/ConfiguredServiceProvider

Docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def createIfNotExists(path):
1212
project = "7bitDI"
1313
copyright = "2023, 7BitCoder Sylwester Dawida"
1414
author = "Sylwester Dawida"
15-
version = "3.2.0"
15+
version = "3.3.0"
1616

1717
extensions = [
1818
"sphinx.ext.autodoc",

Docs/getting-started.rst

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Getting Started
22
==========================
33

4+
Main Features
5+
--------------------
6+
7+
* Implementation separation
8+
* Multiple implementations
9+
* Keyed services
10+
* Service aliases
11+
* Thread safe
12+
* Strong destruction order
13+
414
Supported Platforms
515
--------------------
616

@@ -27,16 +37,16 @@ Installation
2737
**There are a few ways of installation:**
2838

2939

30-
#. Using Cmake fetch content api - Recommended
31-
Update CMakeLists.txt file with following code
40+
#. Using Cmake fetch content API - Recommended
41+
Update CMakeLists.txt file with the following code
3242

3343
.. code-block:: Cmake
3444
3545
include(FetchContent)
3646
FetchContent_Declare(
3747
7bitDI
3848
GIT_REPOSITORY https://github.com/7bitcoder/7bitDI.git
39-
GIT_TAG v3.2.0
49+
GIT_TAG v3.3.0
4050
)
4151
FetchContent_MakeAvailable(7bitDI)
4252
@@ -48,7 +58,7 @@ Installation
4858
.. code-block:: Txt
4959
5060
[requires]
51-
7bitdi/3.2.0
61+
7bitdi/3.3.0
5262
5363
change the version to newer if available, then run the command:
5464

Examples/Guides/ConfiguredServiceProvider.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main()
3939
options.strongDestructionOrder = true;
4040
options.prebuildSingletons = true;
4141
options.checkServiceGlobalUniqueness = false;
42+
options.threadSafe = true;
4243

4344
ServiceProvider provider = ServiceCollection{}
4445
.addSingleton<IService, Service>()

Include/SevenBit/DI/CmakeDef.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
#endif
1414

1515
#define _7BIT_DI_VERSION_MAJOR 3
16-
#define _7BIT_DI_VERSION_MINOR 2
16+
#define _7BIT_DI_VERSION_MINOR 3
1717
/* #undef _7BIT_DI_VERSION_PATCH */

Include/SevenBit/DI/Details/Containers/Impl/ServiceInstancesMap.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ namespace sb::di::details
4242
{
4343
for (auto it = _constructionOrder.rbegin(); it != _constructionOrder.rend(); ++it)
4444
{
45-
if (const auto list = findInstances(*it))
45+
if (const auto listPtr = findInstances(*it))
4646
{
47-
list->clear();
47+
listPtr->clear();
4848
}
4949
}
5050
}

Include/SevenBit/DI/Details/Core/IServiceInstanceProviderRoot.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <mutex>
4+
35
#include "SevenBit/DI/LibraryConfig.hpp"
46

57
#include "SevenBit/DI/Details/Containers/ServiceDescriptorsMap.hpp"
@@ -16,6 +18,8 @@ namespace sb::di::details
1618

1719
virtual ServiceInstancesCreator &getRootCreator() = 0;
1820

21+
virtual std::recursive_mutex *tryGetSyncMutex() = 0;
22+
1923
virtual ~IServiceInstanceProviderRoot() = default;
2024
};
2125
} // namespace sb::di::details

Include/SevenBit/DI/Details/Core/Impl/ServiceInstanceProvider.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace sb::di::details
2727

2828
INLINE IServiceInstanceProvider::Ptr ServiceInstanceProvider::createScope() const
2929
{
30-
return std::make_unique<ServiceInstanceProvider>(_root, _options);
30+
return std::make_unique<ServiceInstanceProvider>(_root, getOptions());
3131
}
3232

3333
INLINE const ServiceInstance &ServiceInstanceProvider::getInstance(const ServiceId &id)

Include/SevenBit/DI/Details/Core/Impl/ServiceInstanceProviderRoot.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ namespace sb::di::details
1010
: ServiceInstanceProvider(*this, options), _descriptorsMap(options.checkServiceGlobalUniqueness),
1111
_singletons(options.strongDestructionOrder)
1212
{
13-
_descriptorsMap.seal();
1413
}
1514

1615
INLINE void ServiceInstanceProviderRoot::init(ServiceProvider &serviceProvider)
1716
{
1817
ServiceInstanceProvider::init(serviceProvider);
18+
_descriptorsMap.seal();
19+
if (getOptions().threadSafe)
20+
{
21+
_mutex = std::make_unique<std::recursive_mutex>();
22+
}
1923
if (getOptions().prebuildSingletons)
2024
{
2125
prebuildSingletons();

Include/SevenBit/DI/Details/Core/ServiceInstanceProvider.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace sb::di::details
1818
class EXPORT ServiceInstanceProvider : public IServiceInstanceProvider
1919
{
2020
ServiceProviderOptions _options;
21+
IServiceInstanceProviderRoot &_root;
2122
ServiceInstancesCreator _instancesCreator;
2223
ServiceAliasesCreator _aliasesCreator;
23-
IServiceInstanceProviderRoot &_root;
2424
ServiceInstancesMap _scoped;
2525

2626
public:
@@ -39,6 +39,8 @@ namespace sb::di::details
3939

4040
[[nodiscard]] IServiceInstanceProvider::Ptr createScope() const override;
4141

42+
std::recursive_mutex *tryGetSyncMutex() override { return _root.tryGetSyncMutex(); }
43+
4244
const ServiceInstance &getInstance(const TypeId serviceTypeId) override
4345
{
4446
return getInstance(ServiceId{serviceTypeId});

Include/SevenBit/DI/Details/Core/ServiceInstanceProviderRoot.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace sb::di::details
1313
{
1414
ServiceDescriptorsMap _descriptorsMap;
1515
ServiceInstancesMap _singletons;
16+
std::unique_ptr<std::recursive_mutex> _mutex;
1617

1718
public:
1819
using Ptr = std::unique_ptr<ServiceInstanceProviderRoot>;
@@ -26,7 +27,6 @@ namespace sb::di::details
2627
_descriptorsMap(begin, end, options.checkServiceGlobalUniqueness),
2728
_singletons(options.strongDestructionOrder)
2829
{
29-
_descriptorsMap.seal();
3030
}
3131

3232
void init(ServiceProvider &serviceProvider) override;
@@ -37,6 +37,8 @@ namespace sb::di::details
3737

3838
ServiceInstancesCreator &getRootCreator() override { return getCreator(); }
3939

40+
std::recursive_mutex *tryGetSyncMutex() override { return _mutex.get(); }
41+
4042
private:
4143
void prebuildSingletons();
4244
};

Include/SevenBit/DI/IServiceInstanceProvider.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <memory>
4+
#include <mutex>
45
#include <optional>
56
#include <string_view>
67

@@ -29,6 +30,13 @@ namespace sb::di
2930
*/
3031
[[nodiscard]] virtual Ptr createScope() const = 0;
3132

33+
/**
34+
* @brief Get sync mutex
35+
* @details Mutex can be used to synchronize service accesses between threads, can be null if synchronization is
36+
* not needed
37+
*/
38+
virtual std::recursive_mutex *tryGetSyncMutex() = 0;
39+
3240
/**
3341
* @brief Returns service instance reference, might throw exception
3442
* @details If service was not registered or was registered as transient, method throws exception

0 commit comments

Comments
 (0)