本文整理汇总了C#中IocContainer.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# IocContainer.Compile方法的具体用法?C# IocContainer.Compile怎么用?C# IocContainer.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IocContainer
的用法示例。
在下文中一共展示了IocContainer.Compile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileDoesntBreakAnything
public void CompileDoesntBreakAnything()
{
// What to do with this ... ?
// To find out if anything was actually compiled it needs to inspect the Expression/Lambda created
using (var container = new IocContainer())
{
// Arrange
container.Register<IFoo>(c => new Foo1());
container.Register<IBar>("bar1name", x => new Bar1());
container.Register<IFooBar>(y => new FooBar((IFoo)y.Resolve(typeof(IFoo)), (IBar)y.Resolve(typeof(IBar), "bar1name")));
container.Register<IFooBar>("foobarname", xyz => new FooBar(xyz.Resolve<IFoo>(), xyz.Resolve<IBar>("bar1name")));
// Act
container.Compile();
var foo = container.Resolve<IFoo>();
var bar = container.Resolve<IBar>("bar1name");
var foobar1 = container.Resolve<IFooBar>();
var foobar2 = container.Resolve<IFooBar>("foobarname");
// Assert
Assert.AreNotSame(foo, null);
Assert.AreNotSame(bar, null);
Assert.AreNotSame(foobar1, null);
Assert.AreNotSame(foobar2, null);
Assert.AreNotSame(foobar1.Foo, null);
Assert.AreNotSame(foobar1.Bar, null);
Assert.AreNotSame(foobar2.Foo, null);
Assert.AreNotSame(foobar2.Bar, null);
Assert.IsInstanceOfType(foo, typeof(Foo1));
Assert.IsInstanceOfType(bar, typeof(Bar1));
Assert.IsInstanceOfType(foobar1, typeof(FooBar));
Assert.IsInstanceOfType(foobar2, typeof(FooBar));
Assert.IsInstanceOfType(foobar1.Foo, typeof(Foo1));
Assert.IsInstanceOfType(foobar1.Bar, typeof(Bar1));
Assert.IsInstanceOfType(foobar2.Foo, typeof(Foo1));
Assert.IsInstanceOfType(foobar2.Bar, typeof(Bar1));
}
}
示例2: CompileWorksWithPropertyInjection
public void CompileWorksWithPropertyInjection()
{
// Can Resolve Property Injection !?
// Make one using Resolve(Type) and one using Resolve<> generic ?
// There need to be a check that the registration was actually compiled
using (var container = new IocContainer())
{
// Arrange
container.Register<IFoo>(c => new Foo1());
container.Register<IBar>(c => new Bar1());
container.Register<IFooBar>(c => new FooBar() { Foo = c.Resolve<IFoo>(), Bar = c.Resolve<IBar>() });
// Act
container.Compile();
var foo = container.Resolve<IFoo>();
var bar = container.Resolve<IBar>();
var foobar = container.Resolve<IFooBar>();
// Assert
Assert.AreNotSame(foo, null);
Assert.AreNotSame(bar, null);
Assert.AreNotSame(foobar, null);
Assert.AreNotSame(foobar.Foo, null);
Assert.AreNotSame(foobar.Bar, null);
}
}
示例3: CompileThrowsExceptionIfRegistrationsAreNotValid
public void CompileThrowsExceptionIfRegistrationsAreNotValid()
{
using (var container = new IocContainer())
{
// Arrange
container.Register<IFoo>(c => new Foo1());
container.Register<IBar>("Bar", x => new Bar1());
container.Register<IFooBar>(y => new FooBar((IFoo)y.Resolve(typeof(IFoo)), (IBar)y.Resolve(typeof(IBar), "Bar")));
container.Register<IFooBar>("FooBar", xyz => new FooBar(xyz.Resolve<IFoo>(), xyz.Resolve<IBar>()));
// Act
container.Compile();
}
}