SlideShare une entreprise Scribd logo
1  sur  11
AlgoWin - James RAVAILLE
http://www.algowin.fr
ASP .NET MVC Core 2
Obtenir les valeurs des
paramètres de fichiers de
configuration dans les vues
Spécialiste de la formation et de l’ingénierie avec la plateforme Microsoft .NET
AlgoWin - James RAVAILLE
PRÉSENTATION
ASP .NET Core propose un ensemble de composants de configuration
qui fournissent un ensemble de paramètres sous la forme clé / valeur
Cet ensemble de données est déterminé lors du démarrage de
l’application Web
Différents formats de données sont pris en charge, avec pour chacun
d’entre eux un fournisseur de données spécifique :
• Fichiers Json, Xml
• Arguments de ligne de commande
• Variables d'environnement
• Objets .NET en mémoire
• …
AlgoWin - James RAVAILLE
SCÉNARIOS
Deux scénarios vous permettent d’accéder aux valeurs des paramètres
de configuration dans les vues :
Avec les classes d’accès et de gestion des
configurations proposées par ASP .NET MVC Core
Avec les classes de mapping permettant d’accéder
aux valeurs des paramètres
Les identifiants des paramètres sont écrits sous
forme de chaînes de caractères
(non fortement typés ; pas de refactoring possible)
Les identifiants des paramètres sont écrits sous
forme de membres d’instance
(fortement typés ; refactoring possible)
1 2
AlgoWin - James RAVAILLE
PRÉSENTATION D’UN FICHIER DE CONFIGURATION
A la racine du projet nous créons (ou modifions s’il existe déjà) le
fichier de configuration nommé appSettings.json pour écrire le
contenu suivant :
"Formation": "ASP .NET Core",
"Formateurs": {
"Principal": "James RAVAILLE"
},
"Plan": [
{
"Libelle": "Les contrôleurs",
"CoefDuree": "0.75"
},
{
"Libelle": "Les vues",
"CoefDuree": "1.5"
}
]
AlgoWin - James RAVAILLE
SCÉNARIO 1 : CONFIGURATION DES VUES
Modifier le fichier _ViewImports.cshtml, afin d’importer dans toutes
les vues l’espace de nom Microsoft.Extensions.Configuration
Ainsi l’ensemble des types de données contenus dans cet espace de
nom, seront utilisables dans les vues de l’application
@using Microsoft.Extensions.Configuration
AlgoWin - James RAVAILLE
SCÉNARIO 1 : LECTURE DE LA VALEUR DES PARAMÈTRES DANS LA VUE
@inject IConfiguration Configuration
Libellé : @Configuration["Formation"]
<br />
Formateur : @Configuration["Formateurs:Principal"]
<br />
Chapitres :
<br />
<ul>
<li>@Configuration["Plan:0:Libelle"] (@Configuration["Plan:0:CoefDuree"] j)</li>
<li>@Configuration["Plan:1:Libelle"] (@Configuration["Plan:1:CoefDuree"] j)</li>
</ul>
Accès à la valeur du paramètre Formation
Accès à la valeur du paramètre Principal,
contenu dans l’élément Formateurs
Affichage des libellés et des coefficients de durée de chaque module de la formation,
contenu dans l’élément Plan. La valeur de l’indice du premier élément est 0
Injection de l’élément de configuration (injection de dépendance)
AlgoWin - James RAVAILLE
SCÉNARIO 1 : RÉSULTAT
AlgoWin - James RAVAILLE
SCÉNARIO 2 : IMPLÉMENTATION D’UNE CLASSE DE PARAMÈTRES
Dans le répertoire Model de l’application, créer une classe nommée
Parametres, contenant l’implémentation des classes suivantes :
public class Parametres
{
public string Formation { get; set; }
public Formateurs Formateurs { get; set; }
public List<ModulePlan> Plan { get; set; }
}
public class Formateurs
{
public string Principal { get; set; }
}
public class ModulePlan
{
public string Libelle { get; set; }
public string CoefDuree { get; set; }
}
Les noms des propriétés sont identiques aux noms
des éléments dans le fichier de configuration
AlgoWin - James RAVAILLE
SCÉNARIO 2 : DÉCLARATION DE L’INJECTION DE DÉPENDANCE
Dans la classe Startup :
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Parametres>(Configuration);
// Instructions supplémentaires
}
Configuration du service permettant d’accéder aux
valeurs des paramètres
AlgoWin - James RAVAILLE
SCÉNARIO 2 : CONFIGURATION DES VUES
Modifier le fichier _ViewImports.cshtml, afin d’importer dans toutes
les vues, l’espace de nom Microsoft.Extensions.Options
Ainsi l’ensemble des types de données contenus dans cet espace de
nom, seront utilisables dans les vues de l’application
@using Microsoft.Extensions.Options
AlgoWin - James RAVAILLE
SCÉNARIO 2 : LECTURE DE LA VALEUR DES PARAMÈTRES DANS LA VUE
@inject IOptions<Parametres> Parametres
Libellé : @Parametres.Value.Formation
<br />
Formateur : @Parametres.Value.Formateurs.Principal
<br />
Chapitres :
<br />
<ul>
<li>@Parametres.Value.Plan[0].Libelle (@Parametres.Value.Plan[0].CoefDuree j)</li>
<li>@Parametres.Value.Plan[1].Libelle (@Parametres.Value.Plan[1].CoefDuree j)</li>
</ul>
Lecture de la valeur du paramètre dont l’identifiant est
Formation dans la configuration de l’application
Injection d’une dépendance dans une vue
Accès à la valeur du paramètre Principal,
contenu dans l’élément Formateurs
Affichage des libellés et des coefficients de durée de chaque module de la formation,
contenu dans l’élément Plan. La valeur de l’indice du premier élément est 0

Contenu connexe

Dernier

MaintenanceLa Maintenance Corrective.ppt
MaintenanceLa Maintenance Corrective.pptMaintenanceLa Maintenance Corrective.ppt
MaintenanceLa Maintenance Corrective.pptssusercbaa22
 
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptxSAID MASHATE
 
Mécanique Automobile LE TURBOCOMPRESSEUR.ppt
Mécanique Automobile LE TURBOCOMPRESSEUR.pptMécanique Automobile LE TURBOCOMPRESSEUR.ppt
Mécanique Automobile LE TURBOCOMPRESSEUR.pptssusercbaa22
 
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptx
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptxSUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptx
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptxssuserbd075f
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfachrafbrahimi1
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film françaisTxaruka
 
gestion des conflits dans les entreprises
gestion des  conflits dans les entreprisesgestion des  conflits dans les entreprises
gestion des conflits dans les entreprisesMajdaKtiri2
 
A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.Franck Apolis
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.Txaruka
 
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...Formation M2i - Intelligence Artificielle Comment booster votre productivité ...
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...M2i Formation
 
Bolero. pptx . Film de A nnne Fontaine
Bolero. pptx . Film   de  A nnne FontaineBolero. pptx . Film   de  A nnne Fontaine
Bolero. pptx . Film de A nnne FontaineTxaruka
 
presentation l'interactionnisme symbolique finale.pptx
presentation l'interactionnisme symbolique  finale.pptxpresentation l'interactionnisme symbolique  finale.pptx
presentation l'interactionnisme symbolique finale.pptxMalikaIdseaid1
 
Approche-des-risques-par-l’analyse-des-accidents-1.pptx
Approche-des-risques-par-l’analyse-des-accidents-1.pptxApproche-des-risques-par-l’analyse-des-accidents-1.pptx
Approche-des-risques-par-l’analyse-des-accidents-1.pptxssusercbaa22
 
Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film françaisTxaruka
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfabatanebureau
 

Dernier (16)

MaintenanceLa Maintenance Corrective.ppt
MaintenanceLa Maintenance Corrective.pptMaintenanceLa Maintenance Corrective.ppt
MaintenanceLa Maintenance Corrective.ppt
 
Evaluación Alumnos de Ecole Victor Hugo
Evaluación Alumnos de Ecole  Victor HugoEvaluación Alumnos de Ecole  Victor Hugo
Evaluación Alumnos de Ecole Victor Hugo
 
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
666148532-Formation-Habilitation-ELECTRIQUE-ENTREPRISE-MARS-2017.pptx
 
Mécanique Automobile LE TURBOCOMPRESSEUR.ppt
Mécanique Automobile LE TURBOCOMPRESSEUR.pptMécanique Automobile LE TURBOCOMPRESSEUR.ppt
Mécanique Automobile LE TURBOCOMPRESSEUR.ppt
 
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptx
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptxSUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptx
SUPPORT DE SUR COURS_GOUVERNANCE_SI_M2.pptx
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdf
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film français
 
gestion des conflits dans les entreprises
gestion des  conflits dans les entreprisesgestion des  conflits dans les entreprises
gestion des conflits dans les entreprises
 
A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.A3iFormations, organisme de formations certifié qualiopi.
A3iFormations, organisme de formations certifié qualiopi.
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.
 
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...Formation M2i - Intelligence Artificielle Comment booster votre productivité ...
Formation M2i - Intelligence Artificielle Comment booster votre productivité ...
 
Bolero. pptx . Film de A nnne Fontaine
Bolero. pptx . Film   de  A nnne FontaineBolero. pptx . Film   de  A nnne Fontaine
Bolero. pptx . Film de A nnne Fontaine
 
presentation l'interactionnisme symbolique finale.pptx
presentation l'interactionnisme symbolique  finale.pptxpresentation l'interactionnisme symbolique  finale.pptx
presentation l'interactionnisme symbolique finale.pptx
 
Approche-des-risques-par-l’analyse-des-accidents-1.pptx
Approche-des-risques-par-l’analyse-des-accidents-1.pptxApproche-des-risques-par-l’analyse-des-accidents-1.pptx
Approche-des-risques-par-l’analyse-des-accidents-1.pptx
 
Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film français
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
 

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

En vedette (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

ASP .NET MVC Core 2 - Obtenir les valeurs des paramètres de fichiers de configuration dans les vues

  • 1. AlgoWin - James RAVAILLE http://www.algowin.fr ASP .NET MVC Core 2 Obtenir les valeurs des paramètres de fichiers de configuration dans les vues Spécialiste de la formation et de l’ingénierie avec la plateforme Microsoft .NET
  • 2. AlgoWin - James RAVAILLE PRÉSENTATION ASP .NET Core propose un ensemble de composants de configuration qui fournissent un ensemble de paramètres sous la forme clé / valeur Cet ensemble de données est déterminé lors du démarrage de l’application Web Différents formats de données sont pris en charge, avec pour chacun d’entre eux un fournisseur de données spécifique : • Fichiers Json, Xml • Arguments de ligne de commande • Variables d'environnement • Objets .NET en mémoire • …
  • 3. AlgoWin - James RAVAILLE SCÉNARIOS Deux scénarios vous permettent d’accéder aux valeurs des paramètres de configuration dans les vues : Avec les classes d’accès et de gestion des configurations proposées par ASP .NET MVC Core Avec les classes de mapping permettant d’accéder aux valeurs des paramètres Les identifiants des paramètres sont écrits sous forme de chaînes de caractères (non fortement typés ; pas de refactoring possible) Les identifiants des paramètres sont écrits sous forme de membres d’instance (fortement typés ; refactoring possible) 1 2
  • 4. AlgoWin - James RAVAILLE PRÉSENTATION D’UN FICHIER DE CONFIGURATION A la racine du projet nous créons (ou modifions s’il existe déjà) le fichier de configuration nommé appSettings.json pour écrire le contenu suivant : "Formation": "ASP .NET Core", "Formateurs": { "Principal": "James RAVAILLE" }, "Plan": [ { "Libelle": "Les contrôleurs", "CoefDuree": "0.75" }, { "Libelle": "Les vues", "CoefDuree": "1.5" } ]
  • 5. AlgoWin - James RAVAILLE SCÉNARIO 1 : CONFIGURATION DES VUES Modifier le fichier _ViewImports.cshtml, afin d’importer dans toutes les vues l’espace de nom Microsoft.Extensions.Configuration Ainsi l’ensemble des types de données contenus dans cet espace de nom, seront utilisables dans les vues de l’application @using Microsoft.Extensions.Configuration
  • 6. AlgoWin - James RAVAILLE SCÉNARIO 1 : LECTURE DE LA VALEUR DES PARAMÈTRES DANS LA VUE @inject IConfiguration Configuration Libellé : @Configuration["Formation"] <br /> Formateur : @Configuration["Formateurs:Principal"] <br /> Chapitres : <br /> <ul> <li>@Configuration["Plan:0:Libelle"] (@Configuration["Plan:0:CoefDuree"] j)</li> <li>@Configuration["Plan:1:Libelle"] (@Configuration["Plan:1:CoefDuree"] j)</li> </ul> Accès à la valeur du paramètre Formation Accès à la valeur du paramètre Principal, contenu dans l’élément Formateurs Affichage des libellés et des coefficients de durée de chaque module de la formation, contenu dans l’élément Plan. La valeur de l’indice du premier élément est 0 Injection de l’élément de configuration (injection de dépendance)
  • 7. AlgoWin - James RAVAILLE SCÉNARIO 1 : RÉSULTAT
  • 8. AlgoWin - James RAVAILLE SCÉNARIO 2 : IMPLÉMENTATION D’UNE CLASSE DE PARAMÈTRES Dans le répertoire Model de l’application, créer une classe nommée Parametres, contenant l’implémentation des classes suivantes : public class Parametres { public string Formation { get; set; } public Formateurs Formateurs { get; set; } public List<ModulePlan> Plan { get; set; } } public class Formateurs { public string Principal { get; set; } } public class ModulePlan { public string Libelle { get; set; } public string CoefDuree { get; set; } } Les noms des propriétés sont identiques aux noms des éléments dans le fichier de configuration
  • 9. AlgoWin - James RAVAILLE SCÉNARIO 2 : DÉCLARATION DE L’INJECTION DE DÉPENDANCE Dans la classe Startup : public void ConfigureServices(IServiceCollection services) { services.Configure<Parametres>(Configuration); // Instructions supplémentaires } Configuration du service permettant d’accéder aux valeurs des paramètres
  • 10. AlgoWin - James RAVAILLE SCÉNARIO 2 : CONFIGURATION DES VUES Modifier le fichier _ViewImports.cshtml, afin d’importer dans toutes les vues, l’espace de nom Microsoft.Extensions.Options Ainsi l’ensemble des types de données contenus dans cet espace de nom, seront utilisables dans les vues de l’application @using Microsoft.Extensions.Options
  • 11. AlgoWin - James RAVAILLE SCÉNARIO 2 : LECTURE DE LA VALEUR DES PARAMÈTRES DANS LA VUE @inject IOptions<Parametres> Parametres Libellé : @Parametres.Value.Formation <br /> Formateur : @Parametres.Value.Formateurs.Principal <br /> Chapitres : <br /> <ul> <li>@Parametres.Value.Plan[0].Libelle (@Parametres.Value.Plan[0].CoefDuree j)</li> <li>@Parametres.Value.Plan[1].Libelle (@Parametres.Value.Plan[1].CoefDuree j)</li> </ul> Lecture de la valeur du paramètre dont l’identifiant est Formation dans la configuration de l’application Injection d’une dépendance dans une vue Accès à la valeur du paramètre Principal, contenu dans l’élément Formateurs Affichage des libellés et des coefficients de durée de chaque module de la formation, contenu dans l’élément Plan. La valeur de l’indice du premier élément est 0