Registration represents a component registration in the IoC container. It maps implementation types to service types (interfaces), specifies lifecycle behavior, and holds the factory for instance creation.
Inversion
public class Registration : Object
| Property | Type | Description |
|---|---|---|
implementation_type |
Type |
The concrete type being registered |
lifecycle |
Lifecycle |
Instance lifecycle (default: TRANSIENT) |
factory |
Factory |
Factory for creating instances |
type_aliases |
ImmutableLot<Type> |
All service types this registration provides |
Registration(Type implementation_type, Factory factory, Lifecycle lifecycle)Creates a new registration. The implementation type is automatically added as a service type.
var factory = new DelegateFactory((scope) => new MyService());
var registration = new Registration(typeof(MyService), factory, Lifecycle.SINGLETON);
as_type(Type type) → RegistrationAdds a service type alias to the registration. Returns this for chaining.
container.register_singleton<MyImplementation>((s) => new MyImplementation())
.as_type(typeof(IServiceA))
.as_type(typeof(IServiceB));
provides(Type type) → boolChecks if this registration provides the specified service type.
if (registration.provides(typeof(ILogger))) {
// Can resolve as ILogger
}
alias_added(Type alias)Emitted when a new type alias is added via as_type(). Used internally by Container and Scope to update their catalogues.
public delegate Object FactoryDelegate(Scope scope) throws Error;
Factory delegate for custom instantiation logic. Receives the current scope for dependency resolution.
// Simple factory
container.register_transient<MyService>((scope) => new MyService());
// Factory with dependencies
container.register_transient<OrderService>((scope) => {
var repo = scope.resolve<IOrderRepository>();
return new OrderService(repo);
});
container.register_singleton<ConsoleLogger>((s) => new ConsoleLogger())
.as_type(typeof(ILogger));
container.register_scoped<UserRepository>((s) => new UserRepository())
.as_type(typeof(IUserReader))
.as_type(typeof(IUserWriter))
.as_type(typeof(IUserRepository));
// Can be resolved as MyService but not as interface
container.register_transient<MyService>((s) => new MyService());
var factory = new MyCustomFactory();
container.register_factory_type(typeof(MyService), factory, Lifecycle.SINGLETON)
.as_type(typeof(IMyService));
When as_type() is called:
type_aliases property is updatedalias_added signal is emittedContainer/Scope adds mapping for the new type
var reg = container.register_singleton<Impl>((s) => new Impl());
// At this point: reg.type_aliases contains [typeof(Impl)]
reg.as_type(typeof(IService));
// Now: reg.type_aliases contains [typeof(Impl), typeof(IService)]
// Container can now resolve both Impl and IService to this registration
Registrations are typically created via container methods:
// These all return Registration for fluent configuration
container.register<T>(factory, lifecycle);
container.register_transient<T>(factory);
container.register_scoped<T>(factory);
container.register_singleton<T>(factory);
Scope-local registrations use the same Registration class:
scope.register_local_scoped<RequestContext>((s) => new RequestContext())
.as_type(typeof(IContext));
The Registration class encapsulates component registration with implementation type, service aliases, lifecycle, and factory, providing fluent configuration via as_type() method chaining.