DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
IServiceCollection.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace DotNetDupe {
8 namespace Extensions {
16 public:
18 IServiceCollection() = default;
20 virtual ~IServiceCollection() = default;
28 IServiceCollection& operator=(IServiceCollection&&) noexcept = default;
29
35 template <typename TService, typename TImplementation, typename... TArgs>
40
45 template <typename TService>
47 this->Add(ServiceDescriptor::Describe(typeid(TService), std::move(fnFactory), ServiceLifetime::Singleton));
48 return *this;
49 }
50
55 template <typename TService>
57 this->Add(ServiceDescriptor(typeid(TService), std::move(pInstance)));
58 return *this;
59 }
60
66 template <typename TService, typename TImplementation, typename... TArgs>
71
76 template <typename TService>
78 this->Add(ServiceDescriptor::Describe(typeid(TService), std::move(fnFactory), ServiceLifetime::Transient));
79 return *this;
80 }
81
87 template <typename TService, typename TImplementation, typename... TArgs>
92
97 template <typename TService>
99 this->Add(ServiceDescriptor::Describe(typeid(TService), std::move(fnFactory), ServiceLifetime::Scoped));
100 return *this;
101 }
102 };
103 }
104 }
105}
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
IServiceCollection()=default
Default constructor initializing an empty collection.
IServiceCollection & AddScoped()
Adds a scoped service of type TService with an implementation of TImplementation.
IServiceCollection(IServiceCollection &&) noexcept=default
Move constructor.
IServiceCollection & AddSingleton()
Adds a singleton service of type TService with an implementation of TImplementation.
IServiceCollection & AddScoped(ServiceDescriptor::FactoryType fnFactory)
Adds a scoped service of type TService with a factory delegate.
IServiceCollection & AddTransient(ServiceDescriptor::FactoryType fnFactory)
Adds a transient service of type TService with a factory delegate.
IServiceCollection & operator=(const IServiceCollection &)=default
Copy assignment operator.
IServiceCollection & AddTransient()
Adds a transient service of type TService with an implementation of TImplementation.
virtual ~IServiceCollection()=default
Virtual destructor for polymorphic cleanup.
IServiceCollection & AddSingleton(ServiceDescriptor::FactoryType fnFactory)
Adds a singleton service of type TService with a factory delegate.
IServiceCollection(const IServiceCollection &)=default
Copy constructor.
IServiceCollection & AddSingleton(DotNetDupe::System::SmartPointer< DotNetDupe::System::Object > pInstance)
Adds a pre-existing singleton instance of type TService.
std::function< DotNetDupe::System::SmartPointer< DotNetDupe::System::Object >(const DotNetDupe::System::SmartPointer< DotNetDupe::System::IServiceProvider > &)> FactoryType
Function signature for dynamic factory service instantiation delegates.
ServiceDescriptor()
Default constructor initializing an empty descriptor.
static ServiceDescriptor Describe(const std::type_index &serviceType, const std::type_index &implementationType, ServiceLifetime eLifetime)
Creates a ServiceDescriptor with the specified service type, implementation type, and lifetime.
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
A unified smart pointer that supports both unique and shared ownership semantics.
@ Scoped
Specifies that a new instance of the service will be created for each scope.
@ Singleton
Specifies that a single instance of the service will be created.
@ Transient
Specifies that a new instance of the service will be created every time it is requested.