本文整理汇总了C#中Container.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# Container.Bind方法的具体用法?C# Container.Bind怎么用?C# Container.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.Bind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read_simple_igc_file_succeeds
public void Read_simple_igc_file_succeeds()
{
var path = "Data/Simple.igc";
var records = new List<Record>();
var container = new Container<RecordType, IRecordReader>();
container.Bind(RecordType.A).To<FlightRecorderRecordReader>();
container.Bind(RecordType.H).To<HeaderRecordReader>();
container.Bind(RecordType.B).To<FixRecordReader>();
using (var stream = new FileStream(path, FileMode.Open))
using (var reader = new IgcReader(stream, new RecordReader(container)))
{
Record record;
while (reader.Read(out record))
records.Add(record);
}
var manufacturerRecord = records.OfType<FlightRecorderRecord>().FirstOrDefault();
Assert.IsNotNull(manufacturerRecord);
Assert.AreEqual(manufacturerRecord.Manufacturer, "XXX");
var fixRecords = records.OfType<FixRecord>().ToList();
Assert.AreEqual(fixRecords.Count, 9);
}
示例2: Dependency
public void Dependency()
{
var container = new Container();
container.Bind<IRepository>().To<ConcreteRepository>();
container.Bind<IService>().To<ConcreteService>();
Assert.That(container.Create<IService>(), Is.TypeOf<ConcreteService>());
}
示例3: Load
public static IgcDocument Load(Stream stream)
{
var container = new Container<RecordType, IRecordReader>();
container.Bind(RecordType.A).To<FlightRecorderRecordReader>();
container.Bind(RecordType.B).To<FixRecordReader>();
container.Bind(RecordType.H).To<HeaderRecordReader>();
var records = ReadDocument(stream, new RecordReader(container));
return new IgcDocument(records);
}
示例4: BindTo
public void BindTo()
{
var container = new Container();
container.Bind<IRepository>().To<ConcreteRepository>();
Assert.That(container.Create<IRepository>(), Is.TypeOf<ConcreteRepository>());
}
示例5: Load
public static IgcDocumentHeader Load(Stream stream)
{
var container = new Container<RecordType, IRecordReader>();
container.Bind(RecordType.H).To<HeaderRecordReader>();
var headerRecords = GetHeaderRecords(stream, new RecordReader(container));
return new IgcDocumentHeader(headerRecords.TakeWhile(r => r.RecordType == RecordType.H));
}