Skip to content

Commit

Permalink
ResetAllMartenDataAsync() also pauses and resumes all async projectio…
Browse files Browse the repository at this point in the history
…ns and subscriptions
  • Loading branch information
jeremydmiller committed Jun 18, 2024
1 parent 0b99b22 commit de0d2a8
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/Marten/HostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,42 @@ public static async Task CleanAllMartenDataAsync<T>(this IHost host) where T : I
/// Call DocumentStore.ResetAllData() on the document store in this host
/// </summary>
/// <param name="host"></param>
public static Task ResetAllMartenDataAsync(this IHost host)
public static async Task ResetAllMartenDataAsync(this IHost host)
{
var coordinator = host.Services.GetService<IProjectionCoordinator>();
if (coordinator != null)
{
await coordinator.PauseAsync().ConfigureAwait(false);
}

var store = host.DocumentStore();
return store.Advanced.ResetAllData(CancellationToken.None);
await store.Advanced.ResetAllData(CancellationToken.None).ConfigureAwait(false);

if (coordinator != null)
{
await coordinator.ResumeAsync().ConfigureAwait(false);
}
}

/// <summary>
/// Call DocumentStore.ResetAllData() on the document store in this host when working with multiple Marten databases
/// </summary>
/// <param name="host"></param>
/// <typeparam name="T"></typeparam>
public static Task ResetAllMartenDataAsync<T>(this IHost host) where T : IDocumentStore
public static async Task ResetAllMartenDataAsync<T>(this IHost host) where T : IDocumentStore
{
var coordinator = host.Services.GetService<IProjectionCoordinator<T>>();
if (coordinator != null)
{
await coordinator.PauseAsync().ConfigureAwait(false);
}

var store = host.DocumentStore<T>();
return store.Advanced.ResetAllData(CancellationToken.None);
await store.Advanced.ResetAllData(CancellationToken.None).ConfigureAwait(false);

if (coordinator != null)
{
await coordinator.ResumeAsync().ConfigureAwait(false);
}
}
}

0 comments on commit de0d2a8

Please sign in to comment.