温莎-从容器中提取瞬变对象
TypedFactory
Logger
Logger
记录器注入:Logger
ILogger
//Install QueueMonitor as SingletonContainer.Register(Component.For<QueueMonitor>().LifestyleSingleton()); //Install DataProcessor as TrnsientContainer.Register(Component.For<DataProcessor>().LifestyleTransient()); Container.Register(Component.For<Data>().LifestyleScoped());public class QueueMonitor{ private dataProcessor; public ILogger Logger { get; set; } public void OnDataReceived(Data data) { //pull the dataProcessor from factory dataProcessor.ProcessData(data); }}public class DataProcessor{ public ILogger Logger { get; set; } public Record[] ProcessData(Data data) { //Data can have multiple Records //Loop through the data and create new set of Records //Is this the correct way to create new records? //How do I use container here and avoid "new" Record record = new Record(/*using the data */); ... //return a list of Records }}public class Record{ public ILogger Logger { get; set; } private _recordNumber; private _recordOwner; public string GetDescription() { Logger.LogDebug("log something"); // return the custom description }}
Record
QueueMonitor
Singleton
Data
Data
OnDataReceived()
哈士奇WWW