Skip to content

in IOptionsSnapshot<T>, T must have a public parameterless contstructor #3078

@cilerler

Description

@cilerler

I would like to be able to log errors in my option/setting file. If I use DI in it, caller says in IOptionsSnapshot<GracePeriodManagerServiceSetting>, GracePeriodManagerServiceSetting must have a public parameterless contstructor how can I make this work?

GracePeriodManagerService.cs

public GracePeriodManagerService(IOptionsSnapshot<GracePeriodManagerServiceSetting> options)
...

GracePeriodManagerServiceSetting.cs

    public class GracePeriodManagerServiceSetting
    {
        private readonly ILogger _logger;
        public GracePeriodManagerServiceSetting(ILogger<GracePeriodManagerServiceSetting> logger)
        {
            _logger = logger;
        }
    ...
    }

appsettings.json

{
  "GracePeriodManagerService": {
    "DelayTime": "1 2 3 4 5 6"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions