DotNetCore.Services
19.7.0
dotnet add package DotNetCore.Services --version 19.7.0
NuGet\Install-Package DotNetCore.Services -Version 19.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetCore.Services" Version="19.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetCore.Services --version 19.7.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetCore.Services, 19.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNetCore.Services as a Cake Addin #addin nuget:?package=DotNetCore.Services&version=19.7.0 // Install DotNetCore.Services as a Cake Tool #tool nuget:?package=DotNetCore.Services&version=19.7.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotNetCore.Services
CsvService
ICsvService
public interface ICsvService
{
Task<List<T>> ReadAsync<T>(string path, char separator = ',') where T : new();
Task WriteAsync<T>(IEnumerable<T> items, string path, char separator = ',');
Task<MemoryStream> WriteAsync<T>(IEnumerable<T> items, char separator = ',');
}
CsvService
public class CsvService : ICsvService
{
public async Task<List<T>> ReadAsync<T>(string path, char separator = ',') where T : new() { }
public async Task WriteAsync<T>(IEnumerable<T> items, string path, char separator = ',') { }
public async Task<MemoryStream> WriteAsync<T>(IEnumerable<T> items, char separator = ',') { }
}
Example
public sealed record Person
{
public int Id { get; set; }
public string Name { get; set; }
}
public static void Main()
{
var people = new List<Person>();
var stream = WriteAsync(people).Result;
WriteAsync(people, "People.csv").Wait();
people = ReadAsync<Person>("People.csv").Result;
}
FileCache
IFileCache
public interface IFileCache
{
void Clear(string file);
T Set<T>(string file, TimeSpan expiration, T value);
bool TryGetValue<T>(string file, out T value);
}
FileCache
public sealed class FileCache : IFileCache
{
public void Clear(string file) { }
public T Set<T>(string file, TimeSpan expiration, T value) { }
public bool TryGetValue<T>(string file, out T value) { }
}
Http
HttpOptions
public sealed record HttpOptions
{
public string BaseAddress { get; set; }
public AuthenticationHeaderValue Authentication { get; set; }
public int TimeoutSeconds { get; set; } = 5;
public int RetryCount { get; set; }
public int RetrySeconds { get; set; }
}
IHttpService
public interface IHttpService
{
Task<HttpStatusCode> DeleteAsync(string uri);
Task<Tuple<HttpStatusCode, TResponse>> GetAsync<TResponse>(string uri);
Task<HttpStatusCode> PatchAsync(string uri, object value);
Task<HttpStatusCode> PostAsync(string uri, object value);
Task<Tuple<HttpStatusCode, TResponse>> PostAsync<TResponse>(string uri, object value);
Task<HttpStatusCode> PutAsync(string uri, object value);
}
HttpService
public abstract class HttpService : IHttpService
{
public async Task<HttpStatusCode> DeleteAsync(string uri) { }
public async Task<Tuple<HttpStatusCode, TResponse>> GetAsync<TResponse>(string uri) { }
public async Task<HttpStatusCode> PatchAsync(string uri, object value) { }
public async Task<HttpStatusCode> PostAsync(string uri, object value) { }
public async Task<Tuple<HttpStatusCode, TResponse>> PostAsync<TResponse>(string uri, object value) { }
public async Task<HttpStatusCode> PutAsync(string uri, object value) { }
}
Example
public interface ITestHttpService : IHttpService { }
public sealed record TestHttpService(HttpOptions options) : HttpService(options), ITestHttpService;
public sealed record Todo(int Id, string Title);
public class Program
{
public static void Main()
{
var baseAddress = "https://jsonplaceholder.typicode.com";
var options = new HttpOptions { BaseAddress = baseAddress };
ITestHttpService httpService = new TestHttpService(options);
var services = new ServiceCollection();
services.AddScoped<ITestHttpService>(provider => httpService);
httpService = services.BuildServiceProvider().GetRequiredService<ITestHttpService>();
var deleteError = httpService.DeleteAsync("todo/1").Result;
var deleteSuccess = httpService.DeleteAsync("todos/1").Result;
var listError = httpService.GetAsync<IEnumerable<Todo>>("todo").Result;
var listSuccess = httpService.GetAsync<IEnumerable<Todo>>("todos").Result;
var getError = httpService.GetAsync<Todo>("todo/1").Result;
var getSuccess = httpService.GetAsync<Todo>("todos/1").Result;
var postError = httpService.PostAsync("todo", default).Result;
var postSuccess = httpService.PostAsync("todos", new { Title = "Title" }).Result;
var postResultError = httpService.PostAsync<Todo>("todo", default).Result;
var postResultSuccess = httpService.PostAsync<Todo>("todos", new { Title = "Title" }).Result;
var putError = httpService.PutAsync("todo/1", default).Result;
var putSuccess = httpService.PutAsync("todos/1", new { Title = "Title" }).Result;
}
}
JsonStringLocalizer
public class JsonStringLocalizer : IStringLocalizer
{
public JsonStringLocalizer(string path) { }
}
Extensions
public static class Extensions
{
public static void AddCsvService(this IServiceCollection services) { }
public static void AddFileCache(this IServiceCollection services) { }
public static void AddJsonStringLocalizer(this IServiceCollection services) { }
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.Localization.Abstractions (>= 9.0.0)
- Polly (>= 8.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on DotNetCore.Services:
Repository | Stars |
---|---|
rafaelfgx/Architecture
.NET 9, Angular 19, Clean Architecture, Clean Code, SOLID Principles, KISS Principle, DRY Principle, Fail Fast Principle, Common Closure Principle, Common Reuse Principle, Acyclic Dependencies Principle, Mediator Pattern, Result Pattern, Folder-by-Feature Structure, Separation of Concerns.
|
Version | Downloads | Last updated |
---|---|---|
19.7.0 | 114 | 11/30/2024 |