HTTPS SSH

DryIoc is fast, small, full-featured IoC Container for .NET

Build status SOQnA Gitter Slack Follow on Twitter

Benchmarks

Performance

  • General use-cases optimized for max speed.
  • Memory footprint preserved as small as possible.

Code/Library

  • No dependencies on the other libraries.
  • Public API is fully documented.

Reliability

  • Unit-test suite with ~850 tests.
  • Thread-safe and lock-free — registrations and resolutions may proceed in parallel without corrupting container state.
  • Detects recursive dependencies aka cycles in object graph.
  • Throws exceptions as early as possible. Exception provides meaningful information about problem and context.
  • Provides diagnostics for potential resolution problems via container.Validate().

Features

  • Register interface/type mapping, additionally supported: registering service once, registration update, removing registration.
  • Register user-defined delegate factory and register existing instance.
  • Register implementation types from provided assemblies with automatically determined service types.
  • Register with service key of arbitrary type, or register multiple non-keyed services.
  • Register with resolution condition.
  • Register with associated metadata object of arbitrary type.
  • Resolve and ResolveMany.
  • Unknown service resolution via Rules.WithUnknownServiceResolvers():
    • Optional automatic concrete types resolution
  • Instance lifetime control or Reuse in DryIoc terms:
    • Nested disposable scopes, ambient scope context.
    • Supported out-of-the-box: Singleton, InResolutionScope, InCurrentScope, InCurrentNamedScope. Plus you can define your own.
    • useParentReuse option for injected dependencies
    • Control reused objects behavior with preventDisposal and weaklyReferenced.
  • Extensive Open-generics support without special syntax: supported constraints, variance, complex nested generic definitions
  • Constructor, property and field injection.
  • Static or instance factory methods in addition to constructor. Factory methods support parameter injection the same way as constructors.
  • Injecting properties and fields into existing object.
  • Creating concrete object without registering it in Container but with injecting its parameters, properties, and fields.
  • Generic wrappers:
    • Service collections: T[], IEnumerable<T>, LazyEnumerable<T>, and I(ReadOnly)Collection|List<T>.
    • Other: Lazy<T>, Func<T>, Meta<TMetadata, T> or Tuple<TMetadata, T>, KeyValuePair<TKey, T>, and user-defined wrappers.
    • Currying over constructor (or factory method) arguments: Func<TArg, T>, Func<TArg1, TArg2, T>, etc.
    • Nested wrappers: e.g. Tuple<SomeMetadata, Func<ISomeService>>[].
  • Composite pattern: Composite itself is excluded from result collection.
  • Decorator pattern.

Companions

DryIocAttributes

DryIocAttributes.dll NuGet Badge
DryIocAttributes (sources) NuGet Badge

  • Extends MEF attributes to cover DryIoc features: metadata, advanced reuses, context based registration, decorators, etc.
  • Does not depend on DryIoc and may be used by other IoC libraries.

DryIocZero

DryIocZero NuGet Badge

Slim IoC Container based on service factory delegates generated at compile-time by DryIoc.

  • Does not depend on DryIoc at run-time.
  • Ensures zero application bootstrapping time associated with IoC registrations.
  • Provides verification of DryIoc registration setup at compile-time by generating service factory delegates. Basically — you can see how DryIoc is creating things.
  • Supports everything registered in DryIoc: reuses, decorators, wrappers, etc.
  • Much smaller and simpler than DryIoc itself. Works standalone without any run-time dependencies.
  • Allows run-time registrations too. You may register instances and delegates at run-time.

Extensions