Skip to content
Alexander Stärk edited this page Jun 14, 2025 · 1 revision

Basilisque - Dependency Injection

This project provides functionality for registering services at an IServiceCollection.
You simply mark your services with attributes. A source generator collects all marked services and generates code to register them.

Getting Started

Install the NuGet package Basilisque.DependencyInjection.
Installing the package will also install the package Basilisque.DependencyInjection.CodeAnalysis as a child dependency. This contains the source generator.

Now you're ready to register your first service.

Features

  • Generates code that registers all marked services of a project.
    This means anyone who uses your project can call a single method to register all of your provided services.

  • The generated code automatically calls the registration methods of all dependencies that also use Basilisque.DependencyInjection.
    This means if you use Basilisque.DependencyInjection in multiple related projects, you have to call the registration method only once and all dependencies will be registered, too.

  • Support for the typical use cases

    • different lifetimes (Transient, Scoped, Singleton)
    • specification of the type as that the service will be registered (e.g. its implemented interfaces)
    • keyed registration
    • factories
    • registration as open generic
    • ImplementsITypeName
      When the service implements an interface with the same name but starting with an I, it will be registered as this interface (e.g. 'PersonService' as 'IPersonService').
    • more complex or specific scenarios can still be handled by custom registration code
  • Marker attributes on interfaces and base classes.
    This means for example, that you can register all implementations of an interface with the same configuration and you don't have to worry about registration whenever you create a new implementation of it.

  • Custom marker attributes
    You can create custom attributes with predefined configuration by inheriting from the provided attributes. Whenever you use your attribute you can be sure, that the same configuration will be used.

  • Multiple registrations of the same service
    A service can have multiple registrations with different configurations.

Clone this wiki locally