Skip to main content

Register Parameters

Register Type-Specific Parameters

If the types are not unique, but you have a dependency you want to inject at startup, you can use the following:

builder.Register<SomeService>(Lifetime.Singleton)
.WithParameter<string>("http://example.com");

Alternatively, you can name a parameter with a key.

builder.Register<SomeService>(Lifetime.Singleton)
.WithParameter("url", "http://example.com");

It can resolve like this:

class SomeService
{
public SomeService(string url) { /* ... */ }
}

This registration only applies when being injected into SomeService.

class OtherClass
{
// ! Error
public OtherClass(string someString) { /* ... */ }
}