public void Removals_dont_cause_exceptions()
        {
            Assert.DoesNotThrow(() =>
            {
                var container = new DefaultContainer();

                container.Register<IFoo>(r => new Foo());
                Assert.IsTrue(container.Remove<IFoo>());
                Assert.IsFalse(container.Remove<IFoo>());

                container.Register<IFoo>("MyFoo", r=> new Foo());
                Assert.IsTrue(container.Remove<IFoo>("MyFoo"));
                Assert.IsFalse(container.Remove<IFoo>("VitaminFail"));
            });
        }
示例#2
0
        public void Removals_dont_cause_exceptions()
        {
            Assert.DoesNotThrow(() =>
            {
                var container = new DefaultContainer();

                container.Register <IFoo>(r => new Foo());
                Assert.IsTrue(container.Remove <IFoo>());
                Assert.IsFalse(container.Remove <IFoo>());

                container.Register <IFoo>("MyFoo", r => new Foo());
                Assert.IsTrue(container.Remove <IFoo>("MyFoo"));
                Assert.IsFalse(container.Remove <IFoo>("VitaminFail"));
            });
        }
示例#3
0
        /// <summary>
        /// 创建容器
        /// </summary>
        /// <param name="configs">依赖配置</param>
        /// <returns></returns>
        public static IContainer CreateContainer(params IConfig[] configs)
        {
            var container = new DefaultContainer();

            container.Register(null, builder => builder.EnableAop(), configs);
            return(container);
        }
示例#4
0
        /// <summary>
        /// 创建容器
        /// </summary>
        /// <param name="configs">依赖配置</param>
        /// <returns></returns>
        public static Sand.Dependency.IContainer CreateContainer(params IConfig[] configs)
        {
            var container = new DefaultContainer();

            container.Register(null, null, configs);
            return(container);
        }
 /// <summary>
 /// Registers the specified object with its related lifetime manager, and the
 /// construction parameters used by the lifetime manager.
 /// </summary>
 /// <param name="serviceType">Type of service to register</param>
 /// <param name="serviceObjectType">Type of object implementing the service</param>
 /// <param name="parameters">Object construction parameters</param>
 /// <param name="properties">Object properties to inject</param>
 /// <param name="ltManager">Lifetime manager object</param>
 /// <param name="customContext"></param>
 public void Register(Type serviceType, Type serviceObjectType,
                      InjectedParameterSettingsCollection parameters = null,
                      PropertySettingsCollection properties          = null, ILifetimeManager ltManager = null,
                      object customContext = null)
 {
     DefaultContainer.Register(serviceType, serviceObjectType, parameters, properties,
                               ltManager, customContext);
 }
示例#6
0
 /// <summary>
 /// 注册依赖
 /// </summary>
 /// <param name="configs">依赖配置</param>
 public static void Register(params IConfig[] configs)
 {
     DefaultContainer.Register(null, builder => builder.EnableAop(), configs);
 }