Skip to content

How can I configure Ocelot programmatically? #2217

Pinned Answered by raman-m
cizu64 asked this question in Q&A
Discussion options

You must be logged in to vote

The second,

Ocelot has no any fluent syntax to build configuration on the fly as it allowed by YARP for example.
But injecting FileConfiguration object is possible during app start in the ConfigurationBuilderExtensions class methods:

public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder, FileConfiguration fileConfiguration,
string primaryConfigFile = null, bool? optional = null, bool? reloadOnChange = null) // optional injections
{
var json = JsonConvert.SerializeObject(fileConfiguration, Formatting.Indented);
return AddOcelotJsonFile(

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@cizu64
Comment options

@cizu64
Comment options

@raman-m
Comment options

Comment options

You must be logged in to vote
4 replies
@raman-m
Comment options

Answer selected by raman-m
@cizu64
Comment options

@raman-m
Comment options

@raman-m
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Configuration Ocelot feature: Configuration
2 participants
Converted from issue

This discussion was converted from issue #2214 on November 24, 2024 10:36.