-
Notifications
You must be signed in to change notification settings - Fork 0
Home
CodeDux edited this page Nov 13, 2014
·
9 revisions
Generic resolve is much more performant than the type overloads
// Singleton with empty constructor
OmnIoCContainer<ISingleton>.Set<Singleton>(Reuse.Singleton);
// Transient with empty constructor
OmnIoCContainer<ITransient>.Set<Transient>(Reuse.Multiple);
// Register multiple singletons with constructor under different names
OmnIoCContainer<ISimpleAdapter>.Set(new SimpleAdapterOne(1), "1");
OmnIoCContainer<ISimpleAdapter>.Set(new SimpleAdapterTwo(2), "2");
// Register multiple transient with constructor under different names
OmnIoCContainer<ISimpleAdapter>.Set(() => new SimpleAdapterThree(3), "3");
OmnIoCContainer<ISimpleAdapter>.Set(() => new SimpleAdapterFour(4), "4");
// Transient with constructor parameters
OmnIoCContainer<ICombined>.Set(() => new Combined(
OmnIoCContainer<ISingleton>.Get(),
OmnIoCContainer<ITransient>.Get()
));
// Transient with IEnumerable<T> constructor parameter
OmnIoCContainer<IImportMultiple>.Set(() => new ImportMultiple(OmnIoCContainer<ISimpleAdapter>.All()));
// Transient with properties
OmnIoCContainer<ISubObject>.Set(() => new SubObject { Service = OmnIoCContainer<IService>.Get() });
// Resolve
var combined = OmnIoCContainer<ICombined>.Get();
// Resolve named
var named = OmnIoCContainer<ISimpleAdapter>.GetNamed("1");
// Resolve all as IEnumerable<T>
var all = OmnIoCContainer<ISimpleAdapter>.All();