A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://z4kn4fein.github.io/stashbox/docs/configuration/container-configuration below:

Container configuration | Stashbox

Container configuration

The container's constructor has an Action<T> parameter used to configure its behavior.

The configuration API is fluent, which means you can chain the configuration methods after each other.

var container = new StashboxContainer(options => options
.WithDisposableTransientTracking()
.WithConstructorSelectionRule(Rules.ConstructorSelection.PreferLeastParameters)
.WithRegistrationBehavior(Rules.RegistrationBehavior.ThrowException));

Re-configuration of the container is also supported by calling its .Configure() method.

var container = new StashboxContainer();
container.Configure(options => options.WithDisposableTransientTracking());

These features are set by default:

With this option, you can enable or disable the tracking of disposable transient objects.

new StashboxContainer(options => options
.WithDisposableTransientTracking());

With this option, you can enable or disable the auto member-injection without attributes.

PropertiesWithPublicSetter

With this flag, the container will perform auto-injection on properties with public setters.

new StashboxContainer(options => options
.WithAutoMemberInjection(
Rules.AutoMemberInjectionRules.PropertiesWithPublicSetter));
PropertiesWithLimitedAccess

With this flag, the container will perform auto-injection on properties even when they don't have a public setter.

new StashboxContainer(options => options
.WithAutoMemberInjection(
Rules.AutoMemberInjectionRules.PropertiesWithLimitedAccess));
PrivateFields

With this flag, the container will perform auto-injection on private fields too.

new StashboxContainer(options => options
.WithAutoMemberInjection(
Rules.AutoMemberInjectionRules.PrivateFields));
Combined rules

You can also combine these flags with bitwise logical operators to get a merged ruleset.

new StashboxContainer(options => options
.WithAutoMemberInjection(Rules.AutoMemberInjectionRules.PrivateFields |
Rules.AutoMemberInjectionRules.PropertiesWithPublicSetter));
Member selection filter

You can pass your own member selection logic to control which members should be auto injected.

new StashboxContainer(options => options
.WithAutoMemberInjection(
filter: member => member.Type != typeof(ILogger)));

With this option, you can enable or disable the auto injection of members defined with C# 11's required keyword.

new StashboxContainer(options => options
.WithRequiredMemberInjection(enabled: false));

note

The required member injection option is enabled by default.

With this option, you can set the constructor selection rule used to determine which constructor the container should use for instantiation.

PreferMostParameters

It prefers the constructor which has the most extended parameter list.

new StashboxContainer(options => options
.WithConstructorSelectionRule(
Rules.ConstructorSelection.PreferMostParameters));
PreferLeastParameters

It prefers the constructor which has the shortest parameter list.

new StashboxContainer(options => options
.WithConstructorSelectionRule(
Rules.ConstructorSelection.PreferLeastParameters));

With this option, you can set the actual behavior used when a new service is registered into the container. These options do not affect named registrations.

SkipDuplications

The container will skip new registrations when the given implementation type is already registered.

new StashboxContainer(options => options
.WithRegistrationBehavior(
Rules.RegistrationBehavior.SkipDuplications));
new StashboxContainer(options => options
.WithRegistrationBehavior(
Rules.RegistrationBehavior.ThrowException));
new StashboxContainer(options => options
.WithRegistrationBehavior(
Rules.RegistrationBehavior.ReplaceExisting));
PreserveDuplications

The container will keep registering the new services with the same implementation type.

new StashboxContainer(options => options
.WithRegistrationBehavior(
Rules.RegistrationBehavior.PreserveDuplications));

With this option, you can set the default lifetime used when a service doesn't have a configured one.

new StashboxContainer(options => options
.WithDefaultLifetime(Lifetimes.Scoped));

With this option, you can enable or disable the life-span and root scope resolution validation on the dependency tree.

new StashboxContainer(options => options
.WithLifetimeValidation());
new StashboxContainer(options => options
.WithVariantGenericTypes());

With this option, you can enable or disable the throwing of a ResolutionFailedException when no services are found for a collection resolution request. When this feature is disabled (default), the container returns an empty array for those request.

new StashboxContainer(options => options
.WithExceptionOverEmptyCollection());

With this option, you can enable or disable conventional resolution, which means the container treats the constructor/method parameter or member names as dependency names used by named resolution.

new StashboxContainer(options => options
.TreatParameterAndMemberNameAsDependencyName());

With this option, you can enable or disable the selection of named registrations when the resolution request is un-named but with the same type.

new StashboxContainer(options => options
.WithNamedDependencyResolutionForUnNamedRequests());
WithUniversalName

Sets the universal name that represents a special name which allows named resolution work for any given name.

new StashboxContainer(options => options
.WithUniversalName("Any"));
WithAdditionalDependencyNameAttribute

Adds an attribute type that is considered a dependency name indicator just like the DependencyName attribute.

new StashboxContainer(options => options
.WithAdditionalDependencyNameAttribute<CustomNameAttribute>());
WithAdditionalDependencyAttribute

Adds an attribute type that is considered a dependency indicator just like the Dependency attribute.

new StashboxContainer(options => options
.WithAdditionalDependencyAttribute<CustomDependencyAttribute>());

With this option, you can enable or disable the default value injection.

new StashboxContainer(options => options
.WithDefaultValueInjection());

With this option, you can enable or disable the resolution of unregistered types. You can also use a configurator delegate to configure the registrations the container will create from the unknown types.

new StashboxContainer(options => options
.WithUnknownTypeResolution(config => config.AsImplementedTypes()));

With this option, you can set an external expression tree compiler. It can be useful on platforms where the IL generator modules are not available; therefore, the expression compiler in Stashbox couldn't work.

new StashboxContainer(options => options
.WithExpressionCompiler(
Rules.ExpressionCompilers.MicrosoftExpressionCompiler));

With this option, you can enable or disable the re-building of singletons in child containers. It allows the child containers to override singleton dependencies in the parent.

new StashboxContainer(options => options
.WithReBuildSingletonsInChildContainer());

note

This feature is not affecting the already built singleton instances in the parent.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4