This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class TaskExtensions | |
| { | |
| /// <summary> | |
| /// The given task will be retried a given number of times. In case of failure a delay is introduced before executing the retry. | |
| /// </summary> | |
| public static async Task<T> Retry<T>( | |
| this Func<Task<T>> taskFactory, | |
| int maxRetries, | |
| TimeSpan delay) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class PagingExtensions | |
| { | |
| public static IQueryable<T> Page<T>(this IQueryable<T> query, int pageIndex, int pageSize) | |
| { | |
| if (pageSize < 1) throw new ArgumentOutOfRangeException(nameof(pageSize), "Must be greater than zero."); | |
| if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex), "Must not be negative."); | |
| if (pageIndex != 0) query = query.Skip(pageIndex * pageSize); | |
| return query.Take(pageSize); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Implementation | |
| public class RawXmlInputFormatter : TextInputFormatter | |
| { | |
| public RawXmlInputFormatter() | |
| { | |
| SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/xml")); | |
| SupportedEncodings.Add(Encoding.UTF8); | |
| } | |
| protected override bool CanReadType(Type type) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| // when using Newtonsoft JSON | |
| services.AddMvc() | |
| .AddJsonOptions(options => | |
| { | |
| options.SerializerSettings.Converters.Add(new StringEnumConverter()); | |
| options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class ServiceCollectionExtensions | |
| { | |
| public static void AddImplementationsOf<T>( | |
| this IServiceCollection services, | |
| Assembly[] assemblies = null, | |
| ServiceLifetime lifetime = ServiceLifetime.Scoped) | |
| { | |
| var serviceType = typeof(T); | |
| services.AddImplementationsOf(serviceType, assemblies, lifetime); | |
| } |