本文整理汇总了C#中Container类的典型用法代码示例。如果您正苦于以下问题:C# Container类的具体用法?C# Container怎么用?C# Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于命名空间,在下文中一共展示了Container类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ContentsMessage
public ContentsMessage(Container container, Contents contents)
{
this.ContainerID = container.ID;
this.Keys = contents.Keys;
this.Data = contents.Data;
this.Meta = contents.Meta;
}
开发者ID:ChrisBrandhorst,项目名称:Touchee_HTTPServer,代码行数:7,代码来源:ContentsMessage.cs
示例2: OnStart
protected override void OnStart(string[] args)
{
base.OnStart(args);
var container = new Container();
host = container.GetInstance<IHostService>();
host.StartServices();
}
开发者ID:htw-bui,项目名称:OrkHub,代码行数:7,代码来源:OrkHubService.cs
示例3: build_with_lambdas_1
public void build_with_lambdas_1()
{
var container = new Container(x => {
// Build by a simple Expression<Func<T>>
x.For<Rule>().Add(() => new ColorRule("Red")).Named("Red");
// Build by a simple Expression<Func<IBuildSession, T>>
x.For<Rule>().Add("Blue", () => { return new ColorRule("Blue"); })
.Named("Blue");
// Build by Func<T> with a user supplied description
x.For<Rule>()
.Add(s => s.GetInstance<RuleBuilder>().ForColor("Green"))
.Named("Green");
// Build by Func<IBuildSession, T> with a user description
x.For<Rule>()
.Add("Purple", s => { return s.GetInstance<RuleBuilder>().ForColor("Purple"); })
.Named("Purple");
});
container.GetInstance<Rule>("Red").ShouldBeOfType<ColorRule>().Color.ShouldEqual("Red");
container.GetInstance<Rule>("Blue").ShouldBeOfType<ColorRule>().Color.ShouldEqual("Blue");
container.GetInstance<Rule>("Green").ShouldBeOfType<ColorRule>().Color.ShouldEqual("Green");
container.GetInstance<Rule>("Purple").ShouldBeOfType<ColorRule>().Color.ShouldEqual("Purple");
}
开发者ID:goraw,项目名称:structuremap,代码行数:26,代码来源:build_by_lambdas.cs
示例4: build_a_func_for_a_concrete_class
public void build_a_func_for_a_concrete_class()
{
var container = new Container();
var func = container.GetInstance<Func<ConcreteClass>>();
func().ShouldNotBeNull();
}
开发者ID:RANENTONG,项目名称:structuremap,代码行数:7,代码来源:Lazy_and_Func_construction_strategy_Tester.cs
示例5: GetContainer
public static IContainer GetContainer()
{
var register = new Registry();
register.IncludeRegistry<MirutradingRegistry>();
IContainer container = new Container(register);
return container;
}
开发者ID:superkklot,项目名称:Mirutrading,代码行数:7,代码来源:ContainerFactory.cs
示例6: as_inline_dependency
public void as_inline_dependency()
{
var container = new Container(x =>
{
// Build by a simple Expression<Func<T>>
x.For<RuleHolder>()
.Add<RuleHolder>()
.Named("Red")
.Ctor<Rule>().Is(() => new ColorRule("Red"));
// Build by a simple Expression<Func<IBuildSession, T>>
x.For<RuleHolder>()
.Add<RuleHolder>()
.Named("Blue").
Ctor<Rule>().Is("The Blue One", () => { return new ColorRule("Blue"); });
// Build by Func<T> with a user supplied description
x.For<RuleHolder>()
.Add<RuleHolder>()
.Named("Green")
.Ctor<Rule>().Is("The Green One", s => s.GetInstance<RuleBuilder>().ForColor("Green"));
// Build by Func<IBuildSession, T> with a user description
x.For<RuleHolder>()
.Add<RuleHolder>()
.Named("Purple")
.Ctor<Rule>()
.Is("The Purple One", s => { return s.GetInstance<RuleBuilder>().ForColor("Purple"); });
});
container.GetInstance<RuleHolder>("Red").Rule.ShouldBeOfType<ColorRule>().Color.ShouldBe("Red");
container.GetInstance<RuleHolder>("Blue").Rule.ShouldBeOfType<ColorRule>().Color.ShouldBe("Blue");
container.GetInstance<RuleHolder>("Green").Rule.ShouldBeOfType<ColorRule>().Color.ShouldBe("Green");
container.GetInstance<RuleHolder>("Purple").Rule.ShouldBeOfType<ColorRule>().Color.ShouldBe("Purple");
}
开发者ID:khellang,项目名称:structuremap,代码行数:35,代码来源:build_by_lambdas.cs
示例7: MockServiceLocator
private void MockServiceLocator()
{
var settings = new ApplicationSettings();
var configReader = new ConfigReaderWriterStub();
configReader.ApplicationSettings = settings;
var registry = new RoadkillRegistry(configReader);
var container = new Container(registry);
container.Configure(x =>
{
x.Scan(a => a.AssemblyContainingType<TestHelpers>());
x.For<IPageRepository>().Use(new PageRepositoryMock());
x.For<IUserContext>().Use(new UserContextStub());
});
LocatorStartup.Locator = new StructureMapServiceLocator(container, false);
DependencyResolver.SetResolver(LocatorStartup.Locator);
var all =
container.Model.AllInstances.OrderBy(t => t.PluginType.Name)
.Select(t => String.Format("{0}:{1}", t.PluginType.Name, t.ReturnedType.AssemblyQualifiedName));
Console.WriteLine(String.Join("\n", all));
}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:25,代码来源:LocatorStartupTests.cs
示例8: use_a_func_for_a_simple_type
public void use_a_func_for_a_simple_type()
{
var container = new Container(x => { x.For<IntHolder>().Use<IntHolder>().Ctor<int>().Is(() => 5); });
container.GetInstance<IntHolder>()
.Number.ShouldBe(5);
}
开发者ID:slahn,项目名称:structuremap,代码行数:7,代码来源:Bug_244_using_Func_of_string_as_a_dependency.cs
示例9: Start
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
inventory = GetComponentInChildren<Container>();
UIManager.instance.playerInventoryPanel.container = inventory;
}
开发者ID:tof31320,项目名称:OfficeStoriesV2,代码行数:8,代码来源:PlayerController.cs
示例10: DifferentObjects_BuildUpClassWithManyClassDependencyProperties_Success
public void DifferentObjects_BuildUpClassWithManyClassDependencyProperties_Success()
{
var c = new Container();
c.RegisterType<EmptyClass>();
c.RegisterType<SampleClass>().AsSingleton();
var sampleClass1 = new SampleClassWithManyClassDependencyProperties();
var sampleClass2 = new SampleClassWithManyClassDependencyProperties();
c.BuildUp(sampleClass1, ResolveKind.PartialEmitFunction);
c.BuildUp(sampleClass2, ResolveKind.PartialEmitFunction);
Assert.IsNotNull(sampleClass1.EmptyClass);
Assert.IsNotNull(sampleClass1.SampleClass);
Assert.IsNotNull(sampleClass1.SampleClass.EmptyClass);
Assert.AreNotEqual(sampleClass1.SampleClass.EmptyClass, sampleClass1.EmptyClass);
Assert.IsNotNull(sampleClass2.EmptyClass);
Assert.IsNotNull(sampleClass2.SampleClass);
Assert.IsNotNull(sampleClass2.SampleClass.EmptyClass);
Assert.AreNotEqual(sampleClass2.SampleClass.EmptyClass, sampleClass2.EmptyClass);
Assert.AreNotEqual(sampleClass1, sampleClass2);
Assert.AreNotEqual(sampleClass1.EmptyClass, sampleClass2.EmptyClass);
Assert.AreEqual(sampleClass1.SampleClass, sampleClass2.SampleClass);
Assert.AreEqual(sampleClass1.SampleClass.EmptyClass, sampleClass2.SampleClass.EmptyClass);
}
开发者ID:amularczyk,项目名称:NiquIoC,代码行数:26,代码来源:BuildUpForClassWithDependencyPropertyTests.cs
示例11: use_a_simple_func_for_string_dependency
public void use_a_simple_func_for_string_dependency()
{
var container = new Container(x => { x.For<Rule>().Use<ColorRule>().Ctor<string>().Is(() => "blue"); });
container.GetInstance<Rule>()
.ShouldBeOfType<ColorRule>().Color.ShouldBe("blue");
}
开发者ID:slahn,项目名称:structuremap,代码行数:7,代码来源:Bug_244_using_Func_of_string_as_a_dependency.cs
示例12: Avoid_NullReferenceException_When_Getting_Undefined_Named_Instances
public void Avoid_NullReferenceException_When_Getting_Undefined_Named_Instances()
{
using (Container myContainer = new Container())
{
myContainer.GetInstance<IndividualContainers>("TEST");
}
}
开发者ID:robjefferies,项目名称:structuremap,代码行数:7,代码来源:IndividualContainers.cs
示例13: InterceptWithGenericArgAndPredicate_TwoInterceptors_InterceptsTheInstanceWithBothInterceptors
public void InterceptWithGenericArgAndPredicate_TwoInterceptors_InterceptsTheInstanceWithBothInterceptors()
{
// Arrange
var logger = new FakeLogger();
var container = new Container();
container.RegisterSingleton<ILogger>(logger);
container.Register<ICommand, CommandThatLogsOnExecute>();
container.InterceptWith<InterceptorThatLogsBeforeAndAfter>(IsACommandPredicate);
container.InterceptWith<InterceptorThatLogsBeforeAndAfter2>(IsACommandPredicate);
container.RegisterInitializer<InterceptorThatLogsBeforeAndAfter>(i => i.BeforeText = "Start1 ");
container.RegisterInitializer<InterceptorThatLogsBeforeAndAfter2>(i => i.BeforeText = "Start2 ");
container.RegisterInitializer<CommandThatLogsOnExecute>(c => c.ExecuteLogMessage = "Executing");
container.RegisterInitializer<InterceptorThatLogsBeforeAndAfter>(i => i.AfterText = " Done1");
container.RegisterInitializer<InterceptorThatLogsBeforeAndAfter2>(i => i.AfterText = " Done2");
// Act
var command = container.GetInstance<ICommand>();
command.Execute();
// Assert
Assert.AreEqual("Start2 Start1 Executing Done1 Done2", logger.Message);
}
开发者ID:MichaelSagalovich,项目名称:SimpleInjector,代码行数:27,代码来源:InterceptorExtensionsTests.cs
示例14: T03_Concrete_Interface
public void T03_Concrete_Interface()
{
var container = new Container(log: Write);
container.RegisterSingleton<ISomeClass>();
container.RegisterSingleton<SomeClass>();
Assert.Equal(container.Resolve<SomeClass>(), container.Resolve<ISomeClass>());
}
开发者ID:dshe,项目名称:StandardContainer,代码行数:7,代码来源:SingletonTest.cs
示例15: setter_failure_description_doesnt_kill_format
public void setter_failure_description_doesnt_kill_format()
{
var c = new Container(ce => { ce.Policies.SetAllProperties(sc => sc.OfType<PropertyType>()); });
Exception<StructureMapBuildException>.ShouldBeThrownBy(() => { c.GetInstance<Root>(); })
.InnerException.ShouldNotBeOfType<FormatException>();
}
开发者ID:slahn,项目名称:structuremap,代码行数:7,代码来源:Exception_Within_Exception_Bug.cs
示例16: should_be_able_to_resolve_from_the_generic_family_expression
public void should_be_able_to_resolve_from_the_generic_family_expression()
{
var widget = new AWidget();
var container = new Container(x => x.For(typeof (IWidget)).Use(widget).Named("mine"));
container.GetInstance<IWidget>("mine").ShouldBeTheSameAs(widget);
}
开发者ID:goraw,项目名称:structuremap,代码行数:7,代码来源:AddValueDirectlyWithGenericUsage.cs
示例17: RegisterClassWithoutDependencyMethod_Fail
public void RegisterClassWithoutDependencyMethod_Fail()
{
var c = new Container();
c.RegisterType<EmptyClass>().AsSingleton();
c.RegisterType<SampleClassWithoutClassDependencyMethod>();
SampleClassWithoutClassDependencyMethod sampleClass = null;
Exception exception = null;
var thread = new Thread(() =>
{
try
{
sampleClass = c.Resolve<SampleClassWithoutClassDependencyMethod>(ResolveKind.FullEmitFunction);
}
catch (Exception ex)
{
exception = ex;
}
});
thread.Start();
thread.Join();
if (exception != null)
{
throw exception;
}
Assert.IsNotNull(sampleClass);
Assert.IsNull(sampleClass.EmptyClass);
}
开发者ID:amularczyk,项目名称:NiquIoC,代码行数:30,代码来源:RegisterClassWithDependencyMethodTests.cs
示例18: get_a_nested_container_for_a_profile
public void get_a_nested_container_for_a_profile()
{
var parent = new Container(x =>
{
x.For<IWidget>().Use<ColorWidget>()
.Ctor<string>("color").Is("red");
x.Profile("green", o =>
{
o.For<IWidget>().Use<ColorWidget>()
.Ctor<string>("color").Is("green");
});
});
var child = parent.GetNestedContainer("green");
var childWidget1 = child.GetInstance<IWidget>();
var childWidget2 = child.GetInstance<IWidget>();
var childWidget3 = child.GetInstance<IWidget>();
var parentWidget = parent.GetInstance<IWidget>();
childWidget1.ShouldBeTheSameAs(childWidget2);
childWidget1.ShouldBeTheSameAs(childWidget3);
childWidget1.ShouldNotBeTheSameAs(parentWidget);
parentWidget.ShouldBeOfType<ColorWidget>().Color.ShouldBe("red");
childWidget1.ShouldBeOfType<ColorWidget>().Color.ShouldBe("green");
}
开发者ID:khellang,项目名称:structuremap,代码行数:29,代码来源:NestedContainerSupportTester.cs
示例19: AddRange
public void AddRange(Container.Info[] cInfo)
{
foreach (Container.Info cI in cInfo)
{
List.Add(cI);
}
}
开发者ID:jpmarques,项目名称:mRemoteNC,代码行数:7,代码来源:Container.List.cs
示例20: Setup
public void Setup() {
_c = new Container();
c1n = new ComponentDefinition<ITestService1, TestService1>(name: "test");
c1n2 = new ComponentDefinition<ITestService1, TestService1>(name: "test2");
c2nn = new ComponentDefinition<ITestService2, TestService2>(priority: 10);
c2n = new ComponentDefinition<ITestService2, TestService2>(name: "test");
}
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:7,代码来源:ContainerInternalsTest.cs
注:本文中的Container类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论