Endpoint configuration for AspNetCore HealthCheck UI at runtime - asp.net-core

I can't find a solution to change endpoint configuration for Asp.net Core HealthCheck UI at runtime.
It can be configured in appsettings.json, or in Startup, but I need to control endpoints at runtime. (e.g. based on integration events)
Any idea?

I found a solution. Using DatabaseStorage, changes in table Configurations is reflected in UI. So implementing simple CRUD features on this table solve the problem.

Related

How to save info in asp.net core startup to be available in app

I have a set of 7 .Net Framework WebApi-based services that all share some common design elements. One shared element is that each will include the service version in the data that it returns from any of its endpoints. In each service, I determine the version from the executing assembly using reflection. I do this in Application_Start and store the result in a property that I create on the Global class that inherits from System.Web.HttpApplication. That way I do the reflection work once and access the result later from each of my methods.
I'm building a new service and this one is built on ASP.NET Core. So I'm trying to figure out how to do the same thing in ASP.NET Core. I can add the reflection logic in Startup.Configure (though it's not really about configuring the Http pipeline which is what Configure is supposed to be doing). Is there a better place than Startup.ConfigureServices or Startup.Configure, to put code that you want to run once on startup?
And where would I store the result to make it readily accessible to each of the downstream methods called from my controller actions?

AspNet Core AppInsights Integration

I am integrating app insights into our AspNet Core app(Target Framework .Net 4.7.1). I have two queries regarding app insights integration.
I am using SimpleInjector IOC, so does it make sense to have below line of code to inject AI into Asp Net Core DI?
services.AddApplicationInsightsTelemetry
I'm having my own Logger class which initializes TelemetryCLient and Logger class is injected using SimpleInjector. So removing above line code will cause an issue or lack of feature from ASPNet Core perspective?
In Asp.Net when we use to add AI it uses to add ApplicationInsights.config file which contains TelemetryInitializer's and TelemetryModules. Whats the best parctice in AspNet Core 2.1 for this? How do I add following TelemetryInitializers?
HttpDependenciesParsingTelemetryInitializer
AzureRoleEnvironmentTelemetryInitializer
AzureWebAppRoleEnvironmentTelemetryInitializer
OperationCorrelationTelemetryInitializer
etc...
Thanks in advance!!!
services.AddApplicationInsightsTelemetry is the easiest way to add application insights to your project. It sets up auto-collection modules for Requests, Dependencies etc, sets up default TelemetryInitializers, TelemetryProcessors (for sampling, live metrics etc.)
if you don't use services.AddApplicationInsightsTelemetry, then you have to programmatically setup all modules/initializers/sampling etc yourself.
There is no ApplicationInsights.config file, so pretty much every customization of the config is to be done through code. Following shows how to add/remove telemetry initializers.
https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Custom-Configuration#configure-telemetry-initializers

Calling a controller inside startup.cs of ASP.Net Core

How can I call a controller method inside startup.cs of ASP.Net Core API? I want to build the cache on application start. Please help.
Thanks in advance
You can not and you shall not. Requests require a connection and at the point in startup the application hasn't been fully configured/booted up yet. Also request require an instance of http context (which basically represents the request), which you can't do from Startup.
Basically it boils down to two options:
Create an powershell/batch/bash script which will call the endpoint, when the application is deployed or started.
If you use IIS or Azure App Service to host your application, you can use Custom Warm-up settings in web.config.
<applicationInitialization>
<add initializationPage="/" hostName="[app hostname]" />
<add initializationPage="/Home/About" hostname="[app hostname]" />
</applicationInitialization>
Option is to refactor your code and pull the things that require caching into a service, then resolve it during application startup and run it once. With ASP.NET Core this should be done in Program.cs's Main method.
See my answer here to see how you could set up warm-up during application startup. The post is about applying migrations, but same technique can be applied for cache warm-up.
Do not run warm-up within Startup.Configure as it was common in ASP.NET Core 1.x, because tools like dotnet ef ... will execute it while discovering the DbContext.
You can pull out logic of a method of the controller in separate service and use it in case of start applications

How to manually reload IOptions in ASP.NET Core RC2 application

I have asp.net Core Rc2 application. To store system setting I use IOptions mechanism which is configured like that:
services.AddOptions();
services.AddSingleton<IOptions<DocumentParameters>, DocumentParametersConfigureOptions>();
All parameters are loaded from database in DocumentParametersConfigureOption class. Thanks to this solution, all system settings can be easily injected into controllers/services and are cached on the server side (they are loaded only at the start of application).
I have also a page where settings can be modified (modified in database). I would like to know how can I reload them when user clicks save without restarting web application service.
Use in memory caching.
On load, put your configuration there. On conclusive connections/resolves, read it from there. When you update it via UI, simply invalidate the cache (i.e. using the cancellation token, see link from above) or just put it manually back in there overriding the existing value.
I would create a second set of IOptions and inject them with either AddTransient or AddScoped.
Transient services will be created every time they are requested, and scoped services will be created once per request.
Here's a link to documentation on service lifetimes.
on asp.net core 1.1 you can achieve this with IOptionsSnapshot

Using the WCF Service Application Template, where is the "service" info

I am using VS2010 and .NET 4.0. When I create a WCF Service Application, I can easily get my service up and running. However, I am unable to find the services information such as binding configuration and address etc. Where does the template store this information so that I can modify. I know I can add my own bindings and address in the config but I want to know what is the default binding WCF template is using and modify accordingly.
I apologize for the simple (dumb) question, but in 3.5 it was in the config upon using the template
This is not something being done by the template. The application is simply using the default WCF configuration settings. See here for futher info.