Skip to content

Add version 3.3.0 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 12, 2024
Merged
3 changes: 1 addition & 2 deletions .github/workflows/MacOs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
{ tool: apple-clang },
{ tool: gcc, ver: 10 },
{ tool: gcc, ver: 11 },
{ tool: gcc, ver: 12 },
{ tool: gcc, ver: 13 } ]
{ tool: gcc, ver: 12 } ]
build_type: [ Release ]
os: [ macos-12 ]
std: [ 17 ]
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15.0)
set(_7BIT_DI_LIBRARY 7bitDI)

set(_7BIT_DI_VERSION_MAJOR 3)
set(_7BIT_DI_VERSION_MINOR 2)
set(_7BIT_DI_VERSION_MINOR 3)
set(_7BIT_DI_VERSION_PATCH 0)

set(_7BIT_DI_VERSION ${_7BIT_DI_VERSION_MAJOR}.${_7BIT_DI_VERSION_MINOR}.${_7BIT_DI_VERSION_PATCH})
Expand Down
1 change: 0 additions & 1 deletion Docs/advanced-guides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ Advanced Guides
advanced-guides/using-aliases
advanced-guides/register-utility-class
advanced-guides/injected-utility-class
advanced-guides/configuring-service-provider
advanced-guides/building-library
12 changes: 6 additions & 6 deletions Docs/advanced-guides/injected-utility-class.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Injected Utility Class
========================================

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

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

.. note::
Class should inherit Injected constructor with 'using Injected::Injected;' in public section
The class should inherit Injected constructor with 'using Injected::Injected;' in the public section

.. literalinclude:: ../../Examples/Guides/InjectedUtilityClass.cpp
:caption: Examples/Guides/InjectedUtilityClass
Expand Down
6 changes: 3 additions & 3 deletions Docs/advanced-guides/register-utility-class.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Register Utility Class
========================================

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

.. note::
Class should inherit Injected constructor with 'using Injected::Injected;' in public section
The class should inherit Injected constructor with 'using Injected::Injected;' in the public section

.. _RegisterService: ../reference/di/utils/register.html
.. _RegisterSingleton: ../reference/di/utils/register.html
Expand Down
4 changes: 2 additions & 2 deletions Docs/advanced-guides/using-aliases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Using Aliases
========================================

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

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

.. literalinclude:: ../../Examples/Guides/ServiceAliases.cpp
Expand Down
1 change: 1 addition & 0 deletions Docs/basic-guides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Basic Guides
basic-guides/injecting-multiple-services
basic-guides/injection-rules
basic-guides/injecting-service-provider
basic-guides/configuring-service-provider
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ read comment documentation for details:
:caption: Include/SevenBit/DI/ServiceProviderOptions.hpp
:language: C++

Pass the custom options to the ServiceCollection buildServiceProvider method to change produced
service provider behaviour
Pass the custom options to the ServiceCollection buildServiceProvider method to change the produced
service provider behavior

.. literalinclude:: ../../Examples/Guides/ConfiguredServiceProvider.cpp
:caption: Examples/Guides/ConfiguredServiceProvider
Expand Down
2 changes: 1 addition & 1 deletion Docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def createIfNotExists(path):
project = "7bitDI"
copyright = "2023, 7BitCoder Sylwester Dawida"
author = "Sylwester Dawida"
version = "3.2.0"
version = "3.3.0"

extensions = [
"sphinx.ext.autodoc",
Expand Down
18 changes: 14 additions & 4 deletions Docs/getting-started.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Getting Started
==========================

Main Features
--------------------

* Implementation separation
* Multiple implementations
* Keyed services
* Service aliases
* Thread safe
* Strong destruction order

Supported Platforms
--------------------

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


#. Using Cmake fetch content api - Recommended
Update CMakeLists.txt file with following code
#. Using Cmake fetch content API - Recommended
Update CMakeLists.txt file with the following code

.. code-block:: Cmake

include(FetchContent)
FetchContent_Declare(
7bitDI
GIT_REPOSITORY https://github.com/7bitcoder/7bitDI.git
GIT_TAG v3.2.0
GIT_TAG v3.3.0
)
FetchContent_MakeAvailable(7bitDI)

Expand All @@ -48,7 +58,7 @@ Installation
.. code-block:: Txt

[requires]
7bitdi/3.2.0
7bitdi/3.3.0

change the version to newer if available, then run the command:

Expand Down
1 change: 1 addition & 0 deletions Examples/Guides/ConfiguredServiceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int main()
options.strongDestructionOrder = true;
options.prebuildSingletons = true;
options.checkServiceGlobalUniqueness = false;
options.threadSafe = true;

ServiceProvider provider = ServiceCollection{}
.addSingleton<IService, Service>()
Expand Down
2 changes: 1 addition & 1 deletion Include/SevenBit/DI/CmakeDef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
#endif

#define _7BIT_DI_VERSION_MAJOR 3
#define _7BIT_DI_VERSION_MINOR 2
#define _7BIT_DI_VERSION_MINOR 3
/* #undef _7BIT_DI_VERSION_PATCH */
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace sb::di::details
{
for (auto it = _constructionOrder.rbegin(); it != _constructionOrder.rend(); ++it)
{
if (const auto list = findInstances(*it))
if (const auto listPtr = findInstances(*it))
{
list->clear();
listPtr->clear();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <mutex>

#include "SevenBit/DI/LibraryConfig.hpp"

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

virtual ServiceInstancesCreator &getRootCreator() = 0;

virtual std::recursive_mutex *tryGetSyncMutex() = 0;

virtual ~IServiceInstanceProviderRoot() = default;
};
} // namespace sb::di::details
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace sb::di::details

INLINE IServiceInstanceProvider::Ptr ServiceInstanceProvider::createScope() const
{
return std::make_unique<ServiceInstanceProvider>(_root, _options);
return std::make_unique<ServiceInstanceProvider>(_root, getOptions());
}

INLINE const ServiceInstance &ServiceInstanceProvider::getInstance(const ServiceId &id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ namespace sb::di::details
: ServiceInstanceProvider(*this, options), _descriptorsMap(options.checkServiceGlobalUniqueness),
_singletons(options.strongDestructionOrder)
{
_descriptorsMap.seal();
}

INLINE void ServiceInstanceProviderRoot::init(ServiceProvider &serviceProvider)
{
ServiceInstanceProvider::init(serviceProvider);
_descriptorsMap.seal();
if (getOptions().threadSafe)
{
_mutex = std::make_unique<std::recursive_mutex>();
}
if (getOptions().prebuildSingletons)
{
prebuildSingletons();
Expand Down
4 changes: 3 additions & 1 deletion Include/SevenBit/DI/Details/Core/ServiceInstanceProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace sb::di::details
class EXPORT ServiceInstanceProvider : public IServiceInstanceProvider
{
ServiceProviderOptions _options;
IServiceInstanceProviderRoot &_root;
ServiceInstancesCreator _instancesCreator;
ServiceAliasesCreator _aliasesCreator;
IServiceInstanceProviderRoot &_root;
ServiceInstancesMap _scoped;

public:
Expand All @@ -39,6 +39,8 @@ namespace sb::di::details

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

std::recursive_mutex *tryGetSyncMutex() override { return _root.tryGetSyncMutex(); }

const ServiceInstance &getInstance(const TypeId serviceTypeId) override
{
return getInstance(ServiceId{serviceTypeId});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace sb::di::details
{
ServiceDescriptorsMap _descriptorsMap;
ServiceInstancesMap _singletons;
std::unique_ptr<std::recursive_mutex> _mutex;

public:
using Ptr = std::unique_ptr<ServiceInstanceProviderRoot>;
Expand All @@ -26,7 +27,6 @@ namespace sb::di::details
_descriptorsMap(begin, end, options.checkServiceGlobalUniqueness),
_singletons(options.strongDestructionOrder)
{
_descriptorsMap.seal();
}

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

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

std::recursive_mutex *tryGetSyncMutex() override { return _mutex.get(); }

private:
void prebuildSingletons();
};
Expand Down
8 changes: 8 additions & 0 deletions Include/SevenBit/DI/IServiceInstanceProvider.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <memory>
#include <mutex>
#include <optional>
#include <string_view>

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

/**
* @brief Get sync mutex
* @details Mutex can be used to synchronize service accesses between threads, can be null if synchronization is
* not needed
*/
virtual std::recursive_mutex *tryGetSyncMutex() = 0;

/**
* @brief Returns service instance reference, might throw exception
* @details If service was not registered or was registered as transient, method throws exception
Expand Down
Loading
Loading