Skip to content

Core Concepts

Alexander Stärk edited this page Sep 25, 2026 · 1 revision

Core Concepts

High-level model

Basilisque Dependency Injection has three core parts:

  • Marker attributes on your service types
  • A source generator that scans these attributes
  • Generated registration code that integrates with IServiceCollection

Generated types and methods

For each participating assembly, the generator creates:

  • A DependencyRegistrator class
  • IServiceCollection extension methods in your root namespace:
    • InitializeDependencies()
    • RegisterServices()

RegisterServices() is the one-line default.

InitializeDependencies() gives you explicit control over the registration builder flow.

Dependency chain behavior

The generated registrator does not only register local services.

It also discovers Basilisque-generated registrators in referenced assemblies and adds them to a dependency collection. This allows registering an entire graph of Basilisque-enabled projects through one top-level call.

Registration attributes

You can annotate classes, structs, and interfaces with:

  • RegisterServiceTransient
  • RegisterServiceScoped
  • RegisterServiceSingleton
  • RegisterService(RegistrationScope...)

Shared options are available through RegisterServiceAttribute, including:

  • As
  • ImplementsITypeName
  • Factory
  • FactoryMethodName
  • Key

See Service Registration and Factories and Keyed Services.

Clone this wiki locally