本文整理汇总了C#中Cat.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# Cat.GetService方法的具体用法?C# Cat.GetService怎么用?C# Cat.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cat
的用法示例。
在下文中一共展示了Cat.GetService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetService
public void GetService()
{
Cat cat = new Cat();
cat.Builders.Add(new LifetimeBuilder());
cat.Builders.Add(new InjectionBuilder());
cat.Builders.Add(new ReflectedBuilder());
Baz baz = new Baz();
cat.Registrations.Add(new CatRegistration(typeof(IFoo), typeof(Foo), new TransientLifetimeManager()));
cat.Registrations.Add(new CatRegistration(typeof(IBar), typeof(Bar), new InstanceLifetimeManager()));
cat.Registrations.Add(new CatRegistration(typeof(IBaz), baz));
var foo1 = cat.GetService(typeof(IFoo));
var foo2 = cat.GetService(typeof(IFoo));
var bar1 = cat.GetService(typeof(IBar));
var bar2 = cat.GetService(typeof(IBar));
var baz1 = cat.GetService(typeof(IBaz));
var baz2 = cat.GetService(typeof(IBaz));
Assert.IsNotNull(foo1);
Assert.IsNotNull(foo2);
Assert.IsNotNull(bar1);
Assert.IsNotNull(bar2);
Assert.IsNotNull(baz1);
Assert.IsNotNull(baz2);
Assert.AreNotSame(foo1, foo2);
Assert.AreSame(bar1, bar2);
Assert.AreSame(baz, baz1);
Assert.AreSame(baz, baz2);
}
示例2: Inject
public void Inject()
{
Cat cat = new Cat();
cat.Builders.Add(new LifetimeBuilder());
cat.Builders.Add(new InjectionBuilder());
cat.Builders.Add(new ReflectedBuilder());
cat.Registrations.Add(new CatRegistration(typeof(IFoo), typeof(Foo), new TransientLifetimeManager()));
cat.Registrations.Add(new CatRegistration(typeof(IBar), typeof(Bar), new TransientLifetimeManager()));
cat.Registrations.Add(new CatRegistration(typeof(IBaz), typeof(Baz), new TransientLifetimeManager()));
cat.Registrations.Add(new CatRegistration(typeof(IGux), typeof(Gux), new TransientLifetimeManager()));
IGux gux = (IGux)cat.GetService(typeof(IGux));
Assert.IsNotNull(gux.Foo);
Assert.IsNotNull(gux.Bar);
Assert.IsNotNull(gux.Baz);
}