DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
IServiceCollection.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
System/Collections/Generic/List.h
"
4
#include "
Extensions/DependencyInjection/ServiceDescriptor.h
"
5
#include "
System/SmartPointer.h
"
6
7
namespace
DotNetDupe
{
8
namespace
Extensions
{
9
namespace
DependencyInjection
{
15
class
IServiceCollection
:
public
DotNetDupe::System::Collections::Generic::List
<ServiceDescriptor> {
16
public
:
18
IServiceCollection
() =
default
;
20
virtual
~IServiceCollection
() =
default
;
22
IServiceCollection
(
const
IServiceCollection
&) =
default
;
24
IServiceCollection
&
operator=
(
const
IServiceCollection
&) =
default
;
26
IServiceCollection
(
IServiceCollection
&&) noexcept = default;
28
IServiceCollection
& operator=(
IServiceCollection
&&) noexcept = default;
29
35
template <typename TService, typename TImplementation, typename... TArgs>
36
IServiceCollection
&
AddSingleton
() {
37
this->
Add
(
ServiceDescriptor::Describe<TService, TImplementation, TArgs...>
(
ServiceLifetime::Singleton
));
38
return
*
this
;
39
}
40
45
template
<
typename
TService>
46
IServiceCollection
&
AddSingleton
(
ServiceDescriptor::FactoryType
fnFactory) {
47
this->
Add
(
ServiceDescriptor::Describe
(
typeid
(TService), std::move(fnFactory),
ServiceLifetime::Singleton
));
48
return
*
this
;
49
}
50
55
template
<
typename
TService>
56
IServiceCollection
&
AddSingleton
(
DotNetDupe::System::SmartPointer<DotNetDupe::System::Object>
pInstance) {
57
this->
Add
(
ServiceDescriptor
(
typeid
(TService), std::move(pInstance)));
58
return
*
this
;
59
}
60
66
template
<
typename
TService,
typename
TImplementation,
typename
... TArgs>
67
IServiceCollection
&
AddTransient
() {
68
this->
Add
(
ServiceDescriptor::Describe<TService, TImplementation, TArgs...>
(
ServiceLifetime::Transient
));
69
return
*
this
;
70
}
71
76
template
<
typename
TService>
77
IServiceCollection
&
AddTransient
(
ServiceDescriptor::FactoryType
fnFactory) {
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>
88
IServiceCollection
&
AddScoped
() {
89
this->
Add
(
ServiceDescriptor::Describe<TService, TImplementation, TArgs...>
(
ServiceLifetime::Scoped
));
90
return
*
this
;
91
}
92
97
template
<
typename
TService>
98
IServiceCollection
&
AddScoped
(
ServiceDescriptor::FactoryType
fnFactory) {
99
this->
Add
(
ServiceDescriptor::Describe
(
typeid
(TService), std::move(fnFactory),
ServiceLifetime::Scoped
));
100
return
*
this
;
101
}
102
};
103
}
104
}
105
}
List.h
Represents a strongly typed list of objects that can be accessed by index mirroring ....
ServiceDescriptor.h
SmartPointer.h
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::IServiceCollection
IServiceCollection()=default
Default constructor initializing an empty collection.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddScoped
IServiceCollection & AddScoped()
Adds a scoped service of type TService with an implementation of TImplementation.
Definition
IServiceCollection.h:88
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::IServiceCollection
IServiceCollection(IServiceCollection &&) noexcept=default
Move constructor.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddSingleton
IServiceCollection & AddSingleton()
Adds a singleton service of type TService with an implementation of TImplementation.
Definition
IServiceCollection.h:36
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddScoped
IServiceCollection & AddScoped(ServiceDescriptor::FactoryType fnFactory)
Adds a scoped service of type TService with a factory delegate.
Definition
IServiceCollection.h:98
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddTransient
IServiceCollection & AddTransient(ServiceDescriptor::FactoryType fnFactory)
Adds a transient service of type TService with a factory delegate.
Definition
IServiceCollection.h:77
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::operator=
IServiceCollection & operator=(const IServiceCollection &)=default
Copy assignment operator.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddTransient
IServiceCollection & AddTransient()
Adds a transient service of type TService with an implementation of TImplementation.
Definition
IServiceCollection.h:67
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::~IServiceCollection
virtual ~IServiceCollection()=default
Virtual destructor for polymorphic cleanup.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddSingleton
IServiceCollection & AddSingleton(ServiceDescriptor::FactoryType fnFactory)
Adds a singleton service of type TService with a factory delegate.
Definition
IServiceCollection.h:46
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::IServiceCollection
IServiceCollection(const IServiceCollection &)=default
Copy constructor.
DotNetDupe::Extensions::DependencyInjection::IServiceCollection::AddSingleton
IServiceCollection & AddSingleton(DotNetDupe::System::SmartPointer< DotNetDupe::System::Object > pInstance)
Adds a pre-existing singleton instance of type TService.
Definition
IServiceCollection.h:56
DotNetDupe::Extensions::DependencyInjection::ServiceDescriptor::FactoryType
std::function< DotNetDupe::System::SmartPointer< DotNetDupe::System::Object >(const DotNetDupe::System::SmartPointer< DotNetDupe::System::IServiceProvider > &)> FactoryType
Function signature for dynamic factory service instantiation delegates.
Definition
ServiceDescriptor.h:22
DotNetDupe::Extensions::DependencyInjection::ServiceDescriptor::ServiceDescriptor
ServiceDescriptor()
Default constructor initializing an empty descriptor.
Definition
ServiceDescriptor.h:25
DotNetDupe::Extensions::DependencyInjection::ServiceDescriptor::Describe
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.
Definition
ServiceDescriptor.h:97
DotNetDupe::System::Collections::Generic::List
Represents a strongly typed list of objects accessible by index.
Definition
List.h:29
DotNetDupe::System::Collections::Generic::List< ServiceDescriptor >::Add
void Add(const ServiceDescriptor &item)
Definition
List.h:138
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::Extensions::DependencyInjection
Definition
IServiceCollection.h:9
DotNetDupe::Extensions::DependencyInjection::ServiceLifetime::Scoped
@ Scoped
Specifies that a new instance of the service will be created for each scope.
Definition
ServiceLifetime.h:15
DotNetDupe::Extensions::DependencyInjection::ServiceLifetime::Singleton
@ Singleton
Specifies that a single instance of the service will be created.
Definition
ServiceLifetime.h:13
DotNetDupe::Extensions::DependencyInjection::ServiceLifetime::Transient
@ Transient
Specifies that a new instance of the service will be created every time it is requested.
Definition
ServiceLifetime.h:17
DotNetDupe::Extensions
Definition
IServiceCollection.h:8
DotNetDupe
Definition
IServiceCollection.h:7
Include
Extensions
DependencyInjection
IServiceCollection.h
Generated by
1.18.0