protected override IIoCContainer CreateTarget() { IKernel kernel = new StandardKernel(); DynamicIoCContainerContext context = new DynamicIoCContainerContext() { Register = registerContext => { IBindingWhenInNamedWithOrOnSyntax <object> binding = kernel.Bind(registerContext.Dependency) .To(registerContext.Implementation); if (registerContext.Settings.IsSingleton()) { binding.InSingletonScope(); } }, RegisterFactory = registerFactoryContext => { IBindingWhenInNamedWithOrOnSyntax <object> binding = kernel.Bind(registerFactoryContext.Type) .ToMethod(internalContext => registerFactoryContext.ObjectFactory()); if (registerFactoryContext.Settings.IsSingleton()) { binding.InSingletonScope(); } }, Resolve = typeToResolve => kernel.GetService(typeToResolve) }; return(new DynamicIoCContainer(context)); }
/// <summary> /// Attaches mechnaism registrations to a dynamic IoC container. /// </summary> /// <typeparam name="TModule">The type of the module to attach.</typeparam> /// <param name="module">The module.</param> /// <param name="contextFactory">The dynaimc IoC context factory.</param> public static void AttachToIoC <TModule>(this TModule module, Action <IDynamicIoCContainerContext> contextFactory) where TModule : ModuleFactoryBase { DynamicIoCContainerContext context = new DynamicIoCContainerContext(); contextFactory(context); module.AttachToIoC(new DynamicIoCContainer(context)); }