/// <summary> /// Helps call the <see cref="IDependencyCoordinator"/> with the correct parameters. /// </summary> /// <param name="coordinator">The instance to use as the dependency coordinator</param> /// <param name="work">The function to be invoked</param> /// <param name="name">The name of the dependency</param> /// <param name="additionalMetadata">Any additional information to be passed into the metadata of the dependency</param> /// <returns>an awaitable <see cref="Task"/></returns> public static Task CallDependency( this IDependencyCoordinator coordinator, Func <Task> work, [CallerMemberName] string?name = null, Dictionary <string, object>?additionalMetadata = null) { var metadata = new DependencyMetadata(name, additionalMetadata); return(coordinator.ExecuteAsync(work, metadata)); }
/// <summary> /// Helps call the <see cref="IDependencyCoordinator"/> with the correct parameters. /// </summary> /// <typeparam name="TResult">The type of the result</typeparam> /// <param name="coordinator">The instance to use as the dependency coordinator</param> /// <param name="work">The function to be invoked</param> /// <param name="name">The name of the dependency</param> /// <param name="addMetadataFunc">Any additional information to be passed into the metadata of the dependency</param> /// <returns>an awaitable <see cref="Task{TResult}"/></returns> public static Task <TResult> CallDependency <TResult>( this IDependencyCoordinator coordinator, Func <Task <TResult> > work, [CallerMemberName] string?name = null, Action <TResult, Dictionary <string, object> >?addMetadataFunc = null) { var metadata = new DependencyMetadata <TResult>(name, addMetadataFunc); return(coordinator.ExecuteAsync(work, metadata)); }
/// <summary> /// The method used to perform the logging of the dependency call /// </summary> /// <param name="work">The work that this coordinator will manage</param> /// <param name="metadata">The metadata related to this dependency call</param> /// <returns>an awaitable <see cref="Task"/></returns> public async Task ExecuteAsync(Func <Task> work, DependencyMetadata metadata) { try { metadata.Start(); await work(); metadata.Complete(); } catch (Exception ex) { metadata.CompleteWithException(ex); throw; } finally { Write(metadata); } }
/// <summary> /// The method used to perform the logging of the dependency call /// </summary> /// <typeparam name="TResult">The type of the result to be returned asynchronously</typeparam> /// <param name="work">The work that this coordinator will manage</param> /// <param name="metadata">The metadata related to this dependency call</param> /// <returns>an awaitable <see cref="Task{TResult}"/></returns> public async Task <TResult> ExecuteAsync <TResult>(Func <Task <TResult> > work, DependencyMetadata <TResult> metadata) { try { metadata.Start(); var result = await work(); metadata.Complete(result); return(result); } catch (Exception ex) { metadata.CompleteWithException(ex); throw; } finally { Write(metadata); } }
void Write(DependencyMetadata metadata) { }