aspnet/DataProtection

Refactor DI support in DataProtection

ajaybhargavb opened this issue · 10 comments

Refactor DI support in DataProtection

@ajaybhargavb How close is this for check-in?

@Eilon Are we taking this in RC2? Or postpone to 1.0.0?

I'll be sending an update to the PR today. But it will not include and test and documentation changes.

Eilon commented

I'd like to get this for RC2 because there are public API changes in it, and I spoke to @ajaybhargavb about it and we had a short email thread too.

Looks like the PR is a little stale at the moment. Do we have any blockers on this?

Spoke to @Eilon and @rynowak this morning. This is being moved to RTM.

@ajaybhargavb You're working on the DI bits, right? I ask because I was having a small problem with DI into the XmlDecryptor. #154

The problem was that DI for XmlDecryptor wasn't working. I wanted to do this ...

public CustomXmlDecryptor(IOptions<CustomDataProtectionOptions> dataProtectionOptions)
{
    _key = dataProtectionOptions.Value.Key;
}

... but that wasn't working. I simply wasn't getting the value. It works using the ctor injection pattern for XmlEncryptor, just not for XmlDecryptor.

With a little help from @tillig, I was able to make it work on the decryptor side with a little hack, I ended up having to do this ...

public CustomXmlDecryptor(IServiceProvider services)
{
    var dataProtectionOptions = 
        services.GetRequiredService<IOptions<CustomDataProtectionOptions>>();
    _key = dataProtectionOptions.Value.Key;
}

Is fixing this something that falls under this issue, or was this problem already addressed do you know?

@guardrex - please make a separate issue for this. Having looked at the code, this isn't something that's been supported so far so it's a feature request

@rynowak Ok, thanks. Will do.

I reopened and re-titled that issue ... it basically describes the difference in success using DI with the ctors of IXmlDecryptor and IXmlEncryptor. Given the workaround there, I'm not blocked of course, so it really is just a nice-to-have if you like the idea.

#154