DotaNet.Services
18.16.2
dotnet add package DotaNet.Services --version 18.16.2
NuGet\Install-Package DotaNet.Services -Version 18.16.2
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="DotaNet.Services" Version="18.16.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotaNet.Services --version 18.16.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotaNet.Services, 18.16.2"
#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 DotaNet.Services as a Cake Addin #addin nuget:?package=DotaNet.Services&version=18.16.2 // Install DotaNet.Services as a Cake Tool #tool nuget:?package=DotaNet.Services&version=18.16.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotaNet.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 | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Localization.Abstractions (>= 8.0.8)
- Polly (>= 8.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.