Class Types
- Namespace
- Cratis.Types
- Assembly
- Cratis.Fundamentals.dll
Represents an implementation of ITypes.
public class Types : ITypes
- Inheritance
-
Types
- Implements
- Inherited Members
- Extension Methods
Constructors
Types()
Initializes a new instance of Types.
public Types()
Remarks
This will automatically set up Types using generated providers when available, and otherwise use the ProjectReferencedAssemblies and PackageReferencedAssemblies providers. DiscoveryMode reports which of the two it chose.
Types(IEnumerable<ICanProvideAssembliesForDiscovery>)
Initializes a new instance of Types.
public Types(IEnumerable<ICanProvideAssembliesForDiscovery> assemblyProviders)
Parameters
assemblyProvidersIEnumerable<ICanProvideAssembliesForDiscovery>Collection of assembly providers.
Fields
Instance
Gets the global instance of Types.
public static readonly Types Instance
Field Value
Remarks
Its recommended to use the singleton defined here, rather than building your own instance. This is due to the performance impact of scanning all assemblies in the application.
Know what it is a snapshot of before relying on it. Being a static field, it is built the first
time anything touches this type and reads GeneratedTypeDiscoveryRegistry exactly
once, at that moment. Providers registered later never reach it - and they do arrive later:
AddBindingsByConvention and AddSelfBindings walk the assembly reference closure and
run module constructors, registering providers for assemblies nothing had touched yet. Touch this
before that walk and the universe is missing everything the walk would have brought in, silently,
because a shorter FindMultiple<T>() result is indistinguishable from a feature nobody
wrote.
A composition root that wants the universe as it stands should let
AddTypeDiscovery() supply it - that reuses one universe per distinct provider set and
rebuilds when the set grows - rather than capturing this field early and holding it. Outside a
container, TypesServiceCollectionExtensions.CurrentTypeUniverse() returns that same
instance, and EnsureProvidersRegistered() is what
makes the provider set complete before either is read.
Properties
All
Gets returns all collected types.
public IEnumerable<Type> All { get; }
Property Value
Assemblies
Gets all assemblies used for type discovery.
public IEnumerable<Assembly> Assemblies { get; }
Property Value
DiscoveryMode
Gets how the assemblies used for type discovery were arrived at.
public TypeDiscoveryMode DiscoveryMode { get; }
Property Value
Remarks
Together with Assemblies this answers, from a running application, which discovery strategy is in force and which assemblies reached it. That matters because Generated captures only the assemblies loaded by the time the type universe was built, and an assembly that arrives later contributes nothing to it - silently, since a shorter FindMultiple<T>() result is indistinguishable from a feature nobody wrote.
Defaulted rather than abstract so that adding it breaks no existing implementation. An implementation that does not say reports Unknown.
Methods
FindMultiple(Type)
Find multiple implementations of a basetype.
public IEnumerable<Type> FindMultiple(Type type)
Parameters
typeTypeBasetype to find for.
Returns
- IEnumerable<Type>
All types implementing or inheriting from the given basetype.
Remarks
If the base type is an interface, it will look for any types implementing the interface. If it is a class, it will find anyone inheriting from that class.
FindMultiple<T>()
Find multiple implementations of a basetype.
public IEnumerable<Type> FindMultiple<T>()
Returns
- IEnumerable<Type>
All types implementing or inheriting from the given basetype.
Type Parameters
TBasetype to find for.
Remarks
If the base type is an interface, it will look for any types implementing the interface. If it is a class, it will find anyone inheriting from that class.
FindSingle(Type)
Find a single implementation of a basetype.
public Type FindSingle(Type type)
Parameters
typeTypeBasetype to find for.
Returns
- Type
Type found.
Remarks
If the base type is an interface, it will look for any types implementing the interface. If it is a class, it will find anyone inheriting from that class.
Exceptions
- MultipleTypesFound
If there is more than one instance found.
FindSingle<T>()
Find a single implementation of a basetype.
public Type FindSingle<T>()
Returns
- Type
Type found.
Type Parameters
TBasetype to find for.
Remarks
If the base type is an interface, it will look for any types implementing the interface. If it is a class, it will find anyone inheriting from that class.
Exceptions
- MultipleTypesFound
If there is more than one instance found.
FindTypeByFullName(string)
Find a single type using the full name, without assembly.
public Type FindTypeByFullName(string fullName)
Parameters
fullNamestringfull name of the type to find.
Returns
- Type
The type is found, null otherwise.