本文整理汇总了C#中IServiceLocator.BuildUp方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceLocator.BuildUp方法的具体用法?C# IServiceLocator.BuildUp怎么用?C# IServiceLocator.BuildUp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceLocator
的用法示例。
在下文中一共展示了IServiceLocator.BuildUp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DispatchMessages
public void DispatchMessages(IServiceLocator childServiceLocator, IEnumerable<object> messages, IMessageContext messageContext) {
Exception exception = null;
try {
OnDispatching(childServiceLocator, messages, messageContext);
foreach (var message in messages) {
var messageType = message.GetType();
foreach (var messageHandlerDispatchInfo in messageHandlers.GetOrderedDispatchInfoFor(messageType))
{
var handler = childServiceLocator.Get(messageHandlerDispatchInfo.InstanceType);
var tryDisposeHandler = false;
if (handler == null)
{
handler = Activator.CreateInstance(messageHandlerDispatchInfo.InstanceType);
tryDisposeHandler = true;
}
childServiceLocator.BuildUp(handler);
try
{
Logger.DebugFormat("Dispatching message {0} to handler {1}", messageType, handler);
messageHandlerDispatchInfo.Invoke(handler, message);
}
finally
{
if (tryDisposeHandler && handler is IDisposable)
{
((IDisposable)handler).Dispose();
}
}
}
}
} catch (Exception e) {
exception = e;
if (exception is TargetInvocationException && exception.InnerException != null) {
exception = e.InnerException;
}
Logger.Warn("Failed Dispatching Messages for message with ID=" + messageContext.MessageId, exception);
OnDispatchException(childServiceLocator, messages, messageContext, exception);
throw;
} finally {
OnDispatched(childServiceLocator, messages, messageContext, exception);
}
}