Advanced features

General information on less commonly used functions.


Go back

Component lifetime

Information on the scope and lifetime of components.

The default behavior of Snow is to create a single instance for each component, and share that instance across all requests for said component.

For most cases, this will be adequate, and indeed making components stateless is generally a good idea. However, sometimes a component has to keep a separate state for each request.

You can use the [RequestScope] attribute on a component class to tell Snow that it should create a new instance of it each time it's injected.

Components inside dependencies

How to deal with components present in a separate assembly.

In large projects, it's common to have several assemblies. If using Snow, you could need to manage components on those assemblies (separate from the "main" assembly with the entry point).

Snow supports this functionality out of the box, with no special changes necessary, in these variants:

  • A component in the main assembly is injected with a component defined in the same assembly (base case). (A -> A)
  • A component in the main assembly is injected with a component defined in another assembly. (B -> A)
  • A component in another assembly is injected with a component defined in the same assembly. (B -> B)
  • A component in another assembly is injected with a component defined in a third assembly. (C -> B)
  • A component in another assembly is injected with a component defined in the main assembly (though this is a weird use case, as it would imply that the dependent assembly is aware of the main assembly). (A -> B)

You're all done!

Snow has no secrets for you now.


Go back