Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASP.NET Core section to demo DI #21740

Merged
merged 3 commits into from
Jun 22, 2021
Merged

Add ASP.NET Core section to demo DI #21740

merged 3 commits into from
Jun 22, 2021

Conversation

lilyjma
Copy link
Contributor

@lilyjma lilyjma commented Jun 9, 2021

Context:

Since Dependency Injection is a key workflow for .NET developers and we've seen requests from customers (twitter, stackoverflow) requesting for DI related content for the new SDKs, we're adding a section about DI for ASP.NET Core in the readme. This has been discussed various folks (David Fowler, David Pine, Scott Addie etc.), and they think it'll be helpful to users.

cc @maggiepint

{
"Search": {
"endpoint": "https://<resource-name>.search.windows.net",
"credential": { "key": "resource key" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to achieve this without hardcoding the API key in a config file? Or is "resource key" the name of an environment variable...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the name of the environment variable. It is the key of the resource. @pakrym is the way to do what Bruce is asking?

Copy link
Contributor

@pakrym pakrym Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IConfiguration system uses many sources of configuration, in ASP.NET Core one of them is environment variables. You can define the same key as SEARCH__CREDENTIAL__KEY="..." environment variable (the __ is used as a section separator). https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context. Can we clarify the example to make it clear that it follows that pattern? We don't want to encourage customers to hard-code secrets in config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this feedback should apply to the other libraries as well, i.e. should we apply this to the Service Bus readme also?

Copy link
Contributor Author

@lilyjma lilyjma Jun 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshfree I'm adding this to all the libraries that have the extension method for DI (some libraries don't have it based on my investigation. I'll create issues for them.) I've added the section for SB already :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the Service Bus readme uses the connection string in the config. In this Readme, it sounds like we are going to be updating it to not include secrets in the config. That is what I am wondering about.

updated where secrets should be stored
removed en-us in link
@lilyjma
Copy link
Contributor Author

lilyjma commented Jun 22, 2021

@pakrym and @brjohnstmsft: sorry for the delay. I've made the changes. Please take a look.

}
}
```
When running in production, it's preferable to use [environment variables](https://docs.microsoft.com/aspnet/core/security/app-secrets?view=aspnetcore-5.0&tabs=windows#environment-variables):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add this information to docs.microsoft.com/en-us/dotnet/azure/sdk/dependency-injection#store-configuration-separately-from-code as well.

}
}
```
You'll also need to provide your resource key to authenticate the client, but you shouldn't be putting that information in the configuration. Instead, when in development, use [User-Secrets](https://docs.microsoft.com/aspnet/core/security/app-secrets?view=aspnetcore-5.0&tabs=windows#how-the-secret-manager-tool-works). Add the following to `secrets.json`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "resource key" common terminology across the Azure SDK? In Search REST API docs, we call these "API keys".

@brjohnstmsft brjohnstmsft merged commit 056b2ae into main Jun 22, 2021
@brjohnstmsft brjohnstmsft deleted the lilyjma-search-DI branch June 22, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants