grandchamp / Identity.Dapper

Identity package that uses Dapper instead EntityFramework for use with .NET Core
MIT License
268 stars 62 forks source link

Dependency injection not working for SqlServerConnectionProvider #79

Closed briankitt closed 6 years ago

briankitt commented 6 years ago

the project as I downloaded it, works fine. But I needed to customize it a bit. I took the project here, and incorporated it into a new .net Core 2.1 project. In the process, I somehow broke it. The part I broke is related to dependency injection, and I'm not seeing the issue.

In my Startup.CS, services.ConfigureDapperConnectionProvider<SqlServerConnectionProvider>(Configuration.GetSection("DapperIdentity")) .ConfigureDapperIdentityCryptography(Configuration.GetSection("DapperIdentityCryptography")) .ConfigureDapperIdentityOptions(new DapperIdentityOptions { UseTransactionalBehavior = false }); I'm debugging it, and when I get to the code below, the _connectionProviderOptions is null. On the sample project provided, it works fine. As far as I can tell, both projects are identical, so I can't see what I broke. The one difference is that the provided project SDK is NetStandard.Library (2.0.3), and my project SDK is Microsoft.NetCore.App (2.1). So that does pull in different versions of the dependent libraries. I suspect that is why it's broken. Where I am confused, is that when I put the dependency in, I put it in as SqlServerConnectionProvider. When it's refenced below, it's referenced as ConnectionProviderOptions. Granted, I'm new to dependency injection, but to me, that should be null, because they are different types. But in the app provided, it does somehow convert them.

`namespace Identity.Dapper.SqlServer.Connections { public class SqlServerConnectionProvider : IConnectionProvider { private readonly IOptions _connectionProviderOptions; private readonly EncryptionHelper _encryptionHelper; public SqlServerConnectionProvider(IOptions connProvOpts, EncryptionHelper encHelper) { _connectionProviderOptions = connProvOpts; _encryptionHelper = encHelper; }

    public DbConnection Create()
    {
        if (_connectionProviderOptions.Value == null)
            throw new ArgumentNullException("There's no DapperIdentity configuration section registered. Please, register the section in appsettings.json or user secrets.");

`

grandchamp commented 6 years ago

Hi @briankitt. Can you provide a repro for your problem? Maybe you can upload it in your github.

briankitt commented 6 years ago

Ok. I apologize. This is the oddest thing. I deleted my projects, and started over from scratch. And it's now all working perfect. I really don't know what I did to break it, but clearly I built the project wrong some how. I worked for easily 3 hours trying to figure out what I did wrong, and just starting over fixed it.

Gremlins......

I would just delete this ticket, but I don't see a way to do that.

Thanks for your time, I appreciate your rapid feedback.

grandchamp commented 6 years ago

Hahahahaha It happens. If you'll implement something that could be used by others, feel free to open a pull request.

briankitt commented 6 years ago

The main thing I'm doing is putting it all in that netcore 2.1 because that's what my requirements are. Other than that no change

-------- Original message -------- From: Nicolas Grandchamp notifications@github.com Date: 10/12/18 4:27 PM (GMT-06:00) To: "grandchamp/Identity.Dapper" Identity.Dapper@noreply.github.com Cc: Brian Kitt brian@kitt.us, Mention mention@noreply.github.com Subject: Re: [grandchamp/Identity.Dapper] Dependency injection not working for SqlServerConnectionProvider (#79)

Hahahahaha

It happens.

If you'll implement something that could be used by others, feel free to open a pull request.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. {"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/grandchamp/Identity.Dapper","title":"grandchamp/Identity.Dapper","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/grandchamp/Identity.Dapper"}},"updates":{"snippets":[{"icon":"PERSON","message":"@grandchamp in #79: Hahahahaha\r\nIt happens.\r\nIf you'll implement something that could be used by others, feel free to open a pull request. "}],"action":{"name":"View Issue","url":"https://github.com/grandchamp/Identity.Dapper/issues/79#issuecomment-429467457"}}} [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/grandchamp/Identity.Dapper/issues/79#issuecomment-429467457", "url": "https://github.com/grandchamp/Identity.Dapper/issues/79#issuecomment-429467457", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } }, { "@type": "MessageCard", "@context": "http://schema.org/extensions", "hideOriginalBody": "false", "originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB", "title": "Re: [grandchamp/Identity.Dapper] Dependency injection not working for SqlServerConnectionProvider (#79)", "sections": [ { "text": "", "activityTitle": "Nicolas Grandchamp", "activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png", "activitySubtitle": "@grandchamp", "facts": [

] } ], "potentialAction": [ { "name": "Add a comment", "@type": "ActionCard", "inputs": [ { "isMultiLine": true, "@type": "TextInput", "id": "IssueComment", "isRequired": false } ], "actions": [ { "name": "Comment", "@type": "HttpPOST", "target": "https://api.github.com", "body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"grandchamp/Identity.Dapper\",\n\"issueId\": 79,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}" } ] }, { "targets": [ { "os": "default", "uri": "https://github.com/grandchamp/Identity.Dapper/issues/79#issuecomment-429467457" } ], "@type": "OpenUri", "name": "View on GitHub" }, { "name": "Unsubscribe", "@type": "HttpPOST", "target": "https://api.github.com", "body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 392729525\n}" } ], "themeColor": "26292E" } ]