Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResetAllMartenDataAsync() also pauses and resumes all async projectio… #3272

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading