本文整理汇总了C#中IServiceLocator.Release方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceLocator.Release方法的具体用法?C# IServiceLocator.Release怎么用?C# IServiceLocator.Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceLocator
的用法示例。
在下文中一共展示了IServiceLocator.Release方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplayEvents
/// <summary>
/// Rebuilds all read models. This is a potentially lengthy operation!
/// </summary>
public static void ReplayEvents(IServiceLocator locator)
{
if (!initialized) throw new InvalidOperationException("The event store must be initialized before first usage.");
IDocumentStore documentStore = null;
try
{
documentStore = (IDocumentStore)locator.Resolve(typeof(IDocumentStore));
DoReplayEvents(locator, documentStore);
}
finally
{
if (documentStore != null)
locator.Release(documentStore);
}
}
示例2: DoReplayEvents
private static void DoReplayEvents(IServiceLocator locator, IDocumentStore documentStore)
{
// wait for indexing to complete
WaitForIndexing(documentStore);
// delete all read models
documentStore.DatabaseCommands.DeleteByIndex("ReadModelIndex", new IndexQuery());
// load all event streams and dispatch events
var dispatcher = new EventDispatcher(locator);
var current = 0;
while (true)
{
IDocumentSession session = null;
try
{
session = (IDocumentSession)locator.Resolve(typeof(IDocumentSession));
var eventsQuery =
session.Query<EventsIndex.Result, EventsIndex>()
.Customize(
x => x.WaitForNonStaleResultsAsOf(DateTime.Now.AddSeconds(15)))
.OrderBy(x => x.ChangeSequence);
var results = eventsQuery.Skip(current).Take(128).ToList();
if (results.Count == 0) break;
foreach (var result in results)
{
var changeSequence = result.ChangeSequence;
var ids = result.Id.Select(x => x.Id);
var streams = session.Load<EventStream>(ids);
var events = from stream in streams
from @event in stream.History
where @event.ChangeSequence == changeSequence
orderby @event.TimeStamp
select new { stream.Id, Event = @event };
foreach (var item in events)
{
dispatcher.Dispatch(item.Event, item.Id);
}
}
session.SaveChanges();
current += results.Count;
}
finally
{
if (session != null)
locator.Release(session);
}
}
}