mayuki / Rin

Request/response Inspector middleware for ASP.NET Core
MIT License
643 stars 24 forks source link

ASP.NET Core 6 - RinOptions not honored #78

Open paralaxsd opened 6 months ago

paralaxsd commented 6 months ago

Hi,

I'm using Rin with an ASP.NET Core 6.0 web API and I found that the options given to Rin via the

public static IRinBuilder AddRin(this IServiceCollection services, Action<RinOptions>? configure = null)

extension method are disregarded. (In my concrete case retention max stays at 100 elements.)

I had a look into the code and it seems to me this is due to the way aforementioned extension method is written: it registers the RinOptions instance previously given to calling end users via lambda expression and registers it as a singleton instance.

Later, services such as InMemoryRecordStorage consume the option via DI but wrapped by IOption.

In order to use options this way however, the RinOptions instance should be registered as an explicit option and since it isn't a default option instance is handed over to the consuming service.

As a workaround, I can set the max number of retained records after calling AddRin() without parameters: services.AddOptions<RinOptions>().Configure(o => o.RequestRecorder.RetentionMaxRequests = 6);

I guess it should probably suffice to adapt the RinOptions registration logic in AddRin (set the case the all other services also consume the instance via IOption<T>).

paralaxsd commented 6 months ago

I just tested recorder excludes and these actually work out of the box, so RinOptions usage varies across the code base.