Skip to content

Provide services to initialization delegate #296

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/BlazorApplicationInsights.Sample.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Main(string[] args)
{
x.ConnectionString = "InstrumentationKey=219f9af4-0842-42c8-a5b1-578f09d2ee27;IngestionEndpoint=https://westus2-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/";
},
async applicationInsights =>
async (_, applicationInsights) =>
{
var telemetryItem = new TelemetryItem()
{
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorApplicationInsights.Sample.Wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task Main(string[] args)
{
config.ConnectionString = "InstrumentationKey=219f9af4-0842-42c8-a5b1-578f09d2ee27;IngestionEndpoint=https://westus2-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/";
},
async applicationInsights =>
async (_, applicationInsights) =>
{
var telemetryItem = new TelemetryItem()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static async Task Main(string[] args)
{
config.ConnectionString = "InstrumentationKey=219f9af4-0842-42c8-a5b1-578f09d2ee27;IngestionEndpoint=https://westus2-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/";
},
async applicationInsights =>
async (_, applicationInsights) =>
{
var telemetryItem = new TelemetryItem()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal class ApplicationInsightsInitConfig
{
public Config? Config { get; set; }

public Func<IApplicationInsights, Task>? OnAppInsightsInit { get; set; }
public Func<IServiceProvider, IApplicationInsights, Task>? OnAppInsightsInit { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using BlazorApplicationInsights.Interfaces;
Expand All @@ -12,6 +13,7 @@ namespace BlazorApplicationInsights;
/// </summary>
public partial class ApplicationInsightsInit
{
[Inject] IServiceProvider ServiceProvider { get; set; }
[Inject] IApplicationInsights ApplicationInsights { get; set; }
[Inject] private IJSRuntime JSRuntime { get; set; }
[Inject] private ApplicationInsightsInitConfig Config { get; set; }
Expand Down Expand Up @@ -54,7 +56,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (firstRender && Config.OnAppInsightsInit != null)
{
await Config.OnAppInsightsInit(ApplicationInsights);
await Config.OnAppInsightsInit(ServiceProvider, ApplicationInsights);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class IServiceCollectionExtensions
/// <param name="onAppInsightsInit">Callback which allows calling Application Insights commands on startup. Note, requires component to be interactive!</param>
/// <param name="addWasmLogger">Adds the ILoggerProvider which ships all logs to Application Insights. This is disabled on Blazor Server.</param>
/// <param name="loggingOptions">Callback for configuring the logging options. Blazor WASM only.</param>
public static IServiceCollection AddBlazorApplicationInsights(this IServiceCollection services, Action<Config>? builder = null, Func<IApplicationInsights, Task>? onAppInsightsInit = null, bool addWasmLogger = true, Action<ApplicationInsightsLoggerOptions>? loggingOptions = null)
public static IServiceCollection AddBlazorApplicationInsights(this IServiceCollection services, Action<Config>? builder = null, Func<IServiceProvider, IApplicationInsights, Task>? onAppInsightsInit = null, bool addWasmLogger = true, Action<ApplicationInsightsLoggerOptions>? loggingOptions = null)
{
var initConfig = new ApplicationInsightsInitConfig();

Expand Down