Skip to content

Commit 88bcba1

Browse files
committed
GetRequiredService
1 parent b6fd824 commit 88bcba1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

WebApiClientCore.Extensions.NewtonsoftJson/Attributes/JsonNetContentAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public string CharSet
3939
protected override Task SetHttpContentAsync(ApiParameterContext context)
4040
{
4141
var name = context.HttpContext.OptionsName;
42-
var options = context.HttpContext.ServiceProvider.GetService<IOptionsMonitor<JsonNetSerializerOptions>>().Get(name);
42+
var options = context.HttpContext.ServiceProvider.GetRequiredService<IOptionsMonitor<JsonNetSerializerOptions>>().Get(name);
4343
var json = context.ParameterValue == null
4444
? string.Empty
4545
: JsonConvert.SerializeObject(context.ParameterValue, options.JsonSerializeOptions);

WebApiClientCore.Extensions.NewtonsoftJson/Attributes/JsonNetReturnAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override async Task SetResultAsync(ApiResponseContext context)
4545
var resultType = context.ActionDescriptor.Return.DataType.Type;
4646

4747
var name = context.HttpContext.OptionsName;
48-
var options = context.HttpContext.ServiceProvider.GetService<IOptionsMonitor<JsonNetSerializerOptions>>().Get(name);
48+
var options = context.HttpContext.ServiceProvider.GetRequiredService<IOptionsMonitor<JsonNetSerializerOptions>>().Get(name);
4949

5050
context.Result = JsonConvert.DeserializeObject(json, resultType, options.JsonDeserializeOptions);
5151
}

0 commit comments

Comments
 (0)