public static ZaabyClientFormatterOptions UseProtobufFormatter(this ZaabyClientFormatterOptions formatterOptions, string mediaType = "application/x-protobuf") { formatterOptions.Serializer = new Serializer(); formatterOptions.MediaType = mediaType; return(formatterOptions); }
public static ZaabyClientFormatterOptions UseUtf8JsonFormatter(this ZaabyClientFormatterOptions formatterOptions, string mediaType = "application/x-utf8json", IJsonFormatterResolver?jsonFormatterResolver = null) { formatterOptions.Serializer = new Serializer(jsonFormatterResolver); formatterOptions.MediaType = mediaType; return(formatterOptions); }
public static ZaabyClientFormatterOptions UseJilFormatter(this ZaabyClientFormatterOptions formatterOptions, string mediaType = "application/x-jil", Options?jilOptions = null) { formatterOptions.Serializer = new Serializer(jilOptions); formatterOptions.MediaType = mediaType; return(formatterOptions); }
public static ZaabyClientFormatterOptions UseMsgPackFormatter(this ZaabyClientFormatterOptions formatterOptions, string mediaType = "application/x-msgpack") { formatterOptions.Serializer = new Serializer(); formatterOptions.MediaType = mediaType; return(formatterOptions); }
public ZaabyHttpClientTextFormatter(ZaabyClientFormatterOptions options) { if (options.Serializer is not ITextSerializer textSerializer) { throw new ArgumentException("The Serializer is not ITextSerializer."); } _serializer = textSerializer; MediaType = options.MediaType; }
public static IServiceCollection AddZaabyClient(this IServiceCollection services, Type serviceDefineType, Dictionary <string, string> configUrls, Action <ZaabyClientFormatterOptions>?optionsFactory = null) { if (configUrls.Count is 0) { return(services); } var typeWithUris = LoadHelper.GetTypePairs(serviceDefineType) .Where(p => p.InterfaceType?.Namespace is not null && p.ImplementationType is null) .Join(configUrls, typePair => typePair.InterfaceType.Namespace, configUrl => configUrl.Key, (typePair, configUrl) => new { Type = typePair.InterfaceType, UriString = configUrl.Value }); var options = new ZaabyClientFormatterOptions(new Serializer(), "application/json"); optionsFactory?.Invoke(options); var formatter = ZaabyHttpClientFormatterFactory.Create(options); foreach (var typeWithUri in typeWithUris) { services.AddHttpClient(typeWithUri.Type.Namespace !, configureClient => { configureClient.BaseAddress = new Uri(typeWithUri.UriString); }); services.AddScoped(typeWithUri.Type, _ => { var implement = ZaabyClientProxy.Create(typeWithUri.Type); if (implement is not ZaabyClientProxy zaabyClientProxy) { return(implement); } zaabyClientProxy.InterfaceType = typeWithUri.Type; zaabyClientProxy.Client = services.BuildServiceProvider() .GetService <IHttpClientFactory>() ! .CreateClient(typeWithUri.Type.Namespace !); zaabyClientProxy.HttpClientFormatter = formatter; return(implement); });
public static ZaabyHttpClientFormatter Create(ZaabyClientFormatterOptions options) => options.Serializer switch {
public ZaabyHttpClientStreamFormatter(ZaabyClientFormatterOptions options) { _serializer = options.Serializer; MediaType = options.MediaType; }