Skip to content

Commit

Permalink
Make Application Insights Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmanuelthiel committed Dec 10, 2023
1 parent 2f46f50 commit 4e8ba07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
31 changes: 14 additions & 17 deletions src/Wemogy.AspNet/Startup/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public static void AddDefaultSetup(this IServiceCollection serviceCollection, St

serviceCollection.AddDefaultControllers(options.DaprEnvironment != null, options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes);

// Health checks
var healthChecksBuilder = serviceCollection.AddHealthChecks();
options.ConfigureHealthCheckBuilder?.Invoke(healthChecksBuilder);
serviceCollection.AddDefaultHealthChecks(options);

serviceCollection.AddDefaultRouting();
}
Expand All @@ -77,6 +75,12 @@ public static void AddDefaultCors(this IServiceCollection serviceCollection)
});
}

public static void AddDefaultHealthChecks(this IServiceCollection serviceCollection, StartupOptions options)
{
var healthChecksBuilder = serviceCollection.AddHealthChecks();
options.ConfigureHealthCheckBuilder?.Invoke(healthChecksBuilder);
}

public static void AddDefaultRouting(this IServiceCollection serviceCollection)
{
// Enforce lowercase routes
Expand Down Expand Up @@ -120,19 +124,7 @@ public static void UseDefaultSetup(this IApplicationBuilder applicationBuilder,
applicationBuilder.UseMiddleware(middleware);
}

if (options.DaprEnvironment != null)
{
applicationBuilder.UseEndpoints(endpoints =>
{
endpoints.MapSubscribeHandler(); // Register endpoints for Dapr PubSub
endpoints.MapControllers();
endpoints.MapHealthChecks("/healthz");
});
}
else
{
applicationBuilder.UseDefaultEndpoints();
}
applicationBuilder.UseDefaultEndpoints(options);
}

public static void UseDefaultRouting(this IApplicationBuilder applicationBuilder)
Expand All @@ -145,12 +137,17 @@ public static void UseDefaultCors(this IApplicationBuilder applicationBuilder)
applicationBuilder.UseCors();
}

public static void UseDefaultEndpoints(this IApplicationBuilder applicationBuilder)
public static void UseDefaultEndpoints(this IApplicationBuilder applicationBuilder, StartupOptions options)
{
applicationBuilder.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/healthz");

if (options.DaprEnvironment != null)
{
endpoints.MapSubscribeHandler(); // Register endpoints for Dapr PubSub
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wemogy.AspNet/Wemogy.AspNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="RestSharp" Version="107.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0" />
<PackageReference Include="Wemogy.Core" Version="3.1.2" />
<PackageReference Include="Wemogy.Core" Version="3.2.0" />
<PackageReference Include="Dapr.AspNetCore" Version="1.10.0" />
</ItemGroup>
</Project>

0 comments on commit 4e8ba07

Please sign in to comment.