Skip to content

API ​

This page shows the public types that applications and tests use. The generated code also uses types from the DependencyModules.Runtime.Helpers namespace. Your code does not usually call these types.

DependencyModules.Runtime ​

ServiceCollectionExtensions ​

MethodFunction
AddModule<T>(this IServiceCollection services)Makes an instance of T and loads it. T must implement IDependencyModule and have a constructor without parameters.
AddModule(this IServiceCollection services, IDependencyModule module)Loads the module.
AddModules(this IServiceCollection services, params IDependencyModule[] modules)Loads the modules in one operation.
AddModules(this IServiceCollection services, IModuleEnvironment? environment, params IDependencyModule[] modules)Loads the modules with the environment.

The return value of all these methods is the service collection.

To call the last method with a null environment, cast the argument: (IModuleEnvironment?)null.

Guide: Load a module.

ModuleEnvironment ​

ModuleEnvironment implements IModuleEnvironment and IEnumerable<KeyValuePair<string, string?>>.

MemberFunction
ModuleEnvironment(string environmentName, IReadOnlyDictionary<string, string?>? values = null)Makes an environment that reads environment variables for the keys that are not in values.
ModuleEnvironment(bool fallBackToEnvironmentVariables, string environmentName, IReadOnlyDictionary<string, string?>? values = null)Makes an environment. If the first argument is false, the environment does not read environment variables.
EnvironmentNameThe name of the environment.
Value(string name)Gives the value for the key, or null.
Add(string key, string? value)Adds a value, or replaces the value for the key.
static CreateDefault()Gives a new instance of the environment of the process.
static NoneAn environment with an empty name and no values.

Guide: Environments.

DependencyModules.Runtime.Attributes ​

For the attributes, refer to Attributes.

BaseServiceAttribute and CrossWireServiceAttribute implement IServiceRegistrationAttribute. This interface has the As, Key, Lifetime, and Using properties. Your code can use the interface to read a service attribute at run time. The generator does not use this interface to find attributes.

DependencyModules.Runtime.Interfaces ​

InterfaceMembersFunction
IDependencyModuleLoadModule, PopulateServiceCollection(IServiceCollection), GetModules()The interface of all modules. The generator implements it on each module. If LoadModule is false, the module does not load. GetModules() gives more modules to load.
IDependencyModuleProviderGetModule()Gives a module. The generated module attributes implement it.
IServiceCollectionConfigurationConfigureServices(IServiceCollection), ConfigureDecorators(IServiceCollection)Registration code in a module.
IEnvironmentServiceCollectionConfigurationConfigureServices(IServiceCollection, IModuleEnvironment)Registration code in a module that reads the environment.
IModuleEnvironmentEnvironmentName, Value(string)The environment.
IModuleEnvironmentProviderProvideEnvironment(MethodInfo testMethod)Gives the environment for a test.

IDependencyModule also has members with the Internal prefix. The generated code uses them. Do not call these members from your code. They have [EditorBrowsable(EditorBrowsableState.Never)]. Thus IntelliSense does not show them in a project that references the package.

DependencyModules.Runtime.Features ​

TypeFunction
IDependencyModuleFeature<TFeature>A module that gets the loaded modules that implement TFeature. Members: Order (default 0) and HandleFeature(IServiceCollection, IEnumerable<TFeature>).
IDependencyModuleApplicatorProviderGives the feature applicators of a module. The generator implements it.
IFeatureApplicatorGives the loaded modules to a feature handler. Members: Order and Apply(IServiceCollection, IReadOnlyList<IDependencyModule>).
FeatureApplicator<TFeature>The IFeatureApplicator that the generated code uses.

Guide: Module features.

DependencyModules.Runtime.Conventions ​

InterfaceFunction
IConventionModuleA module with conventions. Member: Conventions(IConventionDefinitions conventions).
IConventionDefinitionsStarts a convention: RegisterAll<TService>(), RegisterAll(Type serviceType), RegisterAll().
IConventionRegistrationThe calls of a convention chain.

The IConventionRegistration calls:

GroupCalls
LifetimeAsSingleton(), AsScoped(), AsTransient()
ShapeAsSelf(), AsSelfWithInterfaces(), AlsoAsSelf(), As<TService>(), AsMatchingInterface()
Namespace filtersInNamespaceOf<TMarker>(), InNamespaces(params string[]), InExactNamespaces(params string[]), NotInNamespaceOf<TMarker>(), NotInNamespaces(params string[])
Name filtersWithName(params string[]), WithoutName(params string[])
Attribute filtersWithAttribute<TAttribute>(), WithoutAttribute<TAttribute>()
SelectionIncludeBaseClasses(), InAssemblyOf<TMarker>()
RegistrationWithKey(object), Using(RegistrationType)
EnvironmentIfEnvironment(params string[]), IfNotEnvironment(params string[]), IfEnvironmentValue(string), IfEnvironmentValue(string, string), IfNotEnvironmentValue(string), IfNotEnvironmentValue(string, string)

The generator reads these calls when you compile. The methods do not run.

Guide: Conventions.

DependencyModules.Runtime.Interception ​

TypeFunction
IInterceptorTResult Intercept<TResult>(InvocationContext<TResult> context)
IAsyncInterceptorValueTask<TResult> InterceptAsync<TResult>(AsyncInvocationContext<TResult> context)
IAsyncEnumerableInterceptorIAsyncEnumerable<TItem> InterceptStream<TItem>(StreamInvocationContext<TItem> context)
InvocationContext<TResult>Caller, Arguments, Proceed()
AsyncInvocationContext<TResult>Caller, Arguments, ProceedAsync()
StreamInvocationContext<TItem>Caller, Arguments, Proceed()
CallerInfoServiceType, MemberName. ToString() gives Service.Member.
IArgumentsCount, the indexer this[int] with get and set, NameAt(int)
NoResultThe result type of a member that has no return value.

The InvocationState classes are for the generated wrappers.

Guide: Interception.

DependencyModules.Runtime.Helpers ​

The generated code uses these types:

TypeFunction
DependencyRegistry<T>Keeps the registrations and decorators of module T, and loads modules.
DecoratorHelperAdds decorators and interceptor wrappers to the service collection.
DecoratorRegistrationA decorator with its Order.
EnvironmentConditionsExamines the environment conditions.

DependencyModules.Testing.Attributes.Interfaces ​

InterfaceFunction
IModuleTestAttributeModuleTypes. The [ModuleTest] attributes implement it.
ITestMethodContextMethod and Attributes of the test that runs.
ITestServiceSetupAttributeAdds registrations for a test.
IServiceProviderBuilderAttributeBuilds the service provider of a test.
ITestStartupAttributeRuns code after the service provider is available.
ITestParameterValueProviderRegisters services for a parameter and gives the value of the parameter.
IInjectValueAttributeGives constructor arguments for a parameter value.
IMockSupportAttributeMakes mocks for [Mock].
ISharedTestRegistrationSelects the shared services.
ITestContainerSourceCreateAsync() builds a new service provider for the test.
ICurrentTestProviderKey, DisplayName, Assembly, and TryWriteLine for the test that runs. Each test package has an implementation.
IOrderedAttributeOrder, with the default value 10.

Guide: Testing.

DependencyModules.Testing.Impl ​

TypeFunction
TestParameterResolverGets the values of the test parameters. The test packages use it.
TestContainerSourceThe ITestContainerSource implementation.
SharedRegistrationsFinds the shared services of a test.
AttributeUtilityFinds the attributes of a test on the method, the class, and the assembly.
CurrentTestGives the test that runs, from the ICurrentTestProvider of the test package.
TestOutputLoggerProviderAn ILoggerProvider that writes log entries to the output of the test that runs.

Guide: CurrentTest and test output.

MIT license