Namespace Solti.Utils.DI.Interfaces
Classes
AbstractServiceEntry
Describes an abstract service entry.
AbstractServiceEntry.Consts
Contains some constants regarding service resolution.
AspectAttribute
Defines an abstract aspect that can be applied against service interfaces or classes. Aspects are the prefered way to decorate service instances.
// Base class of all the validator attributes
public abstract class ParameterValidatorAttribute : Attribute
{
public abstract void Validate(ParameterInfo param, object value);
}
...
// Sample validator
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class NotNullAttribute : ParameterValidatorAttribute
{
public override void Validate(ParameterInfo param, object value)
{
if (value is null)
throw new ArgumentNullException(param.Name);
}
}
...
public class ParameterValidatorProxy : IInterfaceInterceptor
{
public ParameterValidator(IDependency dependency) {...}
public object? Invoke(IInvocationContext context, CallNextDelegate<IInvocationContext?, object> callNext)
{
foreach (var descr in context.TargetMethod.GetParameters().Select
(
(p, i) => new
{
Parameter = p,
Value = context.Args[i],
Validators = p.GetCustomAttributes<ParameterValidatorAttribute>()
}
))
{
foreach (var validator in descr.Validators)
{
validator.Validate(descr.Parameter, descr.Value);
}
}
return callNext(context);
}
}
...
// Define the comcrete aspect
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class, AllowMultiple = false)]
public sealed class ParameterValidatorAspect : AspectAttribute
{
public ParameterValidatorAspect(): base(typeof(ParameterValidatorProxy)) { }
}
// Then annotate the desired interface ...
[ParameterValidatorAspect]
public interface IService
{
void DoSomething([NotNull] object arg);
}
// ... OR class (recommended)
[ParameterValidatorAspect]
public class Service : IService
{
// Only methods implementing the above declared interface can be annoteted
void DoSomething([NotNull] object arg) { ...}
}
CallNextDelegate<TConext, TResult>
Invokes the next member of chained items.
CircularReferenceException
The exception that is thrown on circular reference.
CreateInterceptorDelegate
Factory responsible for create interceptors.
CreateServiceDelegate
Unconditionaly creates a particular service.
DecoratorDelegate
Defines the layout of functions used to apply proxies.
DecoratorDelegate<TType>
Defines the layout of functions used to apply proxies.
DependencyDescriptor
Describes a dependency (a property or parameter).
FactoryDelegate
Defines the layout of functions used as service factory.
FactoryDelegate<TType>
Defines the layout of functions used as service factory.
IInjectorBasicExtensions
Defines basic extensions for the IInjector interface.
InjectAttribute
Marks a property to be resolved:
class DependantService: IDependantService
{
[Inject]
public IDependencyService Dependency { get; init; }
}
IScopeFactoryExtensions
Defines some extensions for the IScopeFactory interface.
IServiceCollectionBasicExtensions
Defines basic extensions for the IServiceCollection interface.
IServiceId.Comparer
Related comparer.
IServiceId.Formatter
Related formatter
IServiceProviderBasicExtensions
Defines basic extensions for the System.IServiceProvider interface.
LifetimeBase
Represents the contract of service lifetime descriptors.
OptionsAttribute
Controls the IInjector during the dependency resolution.
RequestNotAllowedException
The exception that is thrown when a service request is not allowed.
ScopeOptions
Specifies the scope behavior.
ServiceActivatorAttribute
Marks a constructor to be used by the injector. Useful in case of multiple constructors.
class MyService
{
[ServiceActivator]
public MyService(IDependency dep) : this(dep, 1986) {...}
public MyService(IDependency dep, int foo) {...}
}
ServiceAlreadyRegisteredException
The exception that is thrown on duplicate service registration.
ServiceDisposalMode
Contains the possible disposal modes.
ServiceEntryExtensions
Defines some extensions for the AbstractServiceEntry class.
ServiceEntryFeatures
Describes the features of an AbstractServiceEntry
ServiceEntryStates
Describes the actual state of an AbstractServiceEntry
ServiceId
Default IServiceId implementation
ServiceNotFoundException
The exception that is thrown when a service could not be found.
ServiceOptions
Specifies the general service behavior.
ServiceResolutionMode
Specifies when the system should build the dependency graph.
Interfaces
IBuildContext
Context used during the build phase.
IDependencyResolver
Specifies the contract how to resolve a dependency (System.Reflection.ParameterInfo or System.Reflection.PropertyInfo).
IFactoryVisitor
Defines the contract of visiting factory methods.
IHasTag
Classes implementing this interface may have a tag.
IInjector
Provides the mechanism for injecting resources.
IInterfaceInterceptor
Describes the contract how to implement an interface interceptor.
IInvocationContext
Contains the related context of a perticular method invocation
ILazy<TInterfce>
Lazily resolves a dependency
IProxyEngine
Describes how to wrap a proxy engine to be compatible with this library.
IScopeFactory
Provides a thread safe way to create new scopes.
IServiceActivator
Describes the contract how to create servive instances.
IServiceCollection
Specifies the contract of service entry sets.
IServiceId
Describes an abstract service identifier.