Skip to content

Setup getting started

Steven Robbins edited this page Jan 31, 2011 · 5 revisions

Setup / Getting Started

In addition to more "traditional" registration/setup, TinyIoC also provides a default singleton implementation and "AutoRegister" for automatic discovery/registration of types.

// TinyIoC provides a lazyily constructed singleton
// version of itself if you want to use it.
var container = TinyIoCContainer.Current;

// By default we can resolve concrete types without
// registration
var instance = container.Resolve<MyConcreteType>();

// We can automatically register all concrete types, abstract base classes
// and interfaces with a single call.
container.AutoRegister();
var implementation = container.Resolve<IMyInterface>();

// By default we silently ignore duplicate implementations,
// but we can choose to throw a meaningful exception that contains
// the interface/base type and all the potential implementations:
container.AutoRegister(false);

AutoRegister can also be combined with "normal" registrations so autoregister can handle the majority of registrations but you can "override" specific registrations afterwards.

For more information on the more traditional registration interface see Registration / Lifetimes.

Clone this wiki locally