有一个关于如何在.net核心控制台应用程序上创建强类型配置的stackoverflow答案here,但我的问题是如何将这种强类型配置传递给其他服务;
类似的东西
<template>
<div>
<input type="text" />
<kendo-grid :data-source="localDataSource" v-model="selectedItem" @rowClick="onRowClick">
<kendo-grid-column @select="onRowClick" :selectable="true" :width="60">mne</kendo-grid-column>
<kendo-grid-column :field="'ProductName'" :width="180"></kendo-grid-column>
<kendo-grid-column :field="'UnitPrice'" :title="'Unit Price'" :width="120" :format="'{0:c}'"></kendo-grid-column>
<kendo-grid-column :field="'Category'" :title="'Category'" :width="180"></kendo-grid-column>
<kendo-grid-column :field="'Discontinued'" :width="120"></kendo-grid-column>
</kendo-grid>
{{selectedItem}}
</div>
</template>
<script>
import Vue from "vue";
import { GridInstaller } from "@progress/kendo-grid-vue-wrapper";
Vue.use(GridInstaller);
export default {
methods: {
onRowClick (event) {
console.log('$> ', event);
},
},
data() {
return {
selectedItem: [],
localDataSource: {
data: [
{
ProductID: 1,
ProductName: "Chai",
UnitPrice: 18,
UnitsInStock: 39,
Discontinued: false,
Category: "Beverages",
},
{
ProductID: 4,
ProductName: "Chef Anton",
UnitPrice: 22,
UnitsInStock: 53,
Discontinued: false,
Category: "Beverages",
},
{
ProductID: 5,
ProductName: "Chef Gumbo Mix",
UnitPrice: 21.35,
UnitsInStock: 0,
Discontinued: true,
Category: "Dairy Products",
},
{
ProductID: 6,
ProductName: "Boysenberry Spread",
UnitPrice: 25,
UnitsInStock: 120,
Discontinued: false,
Category: "Condiments",
},
],
},
};
},
};
</script>
<style>
</style>
答案 0 :(得分:0)
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions<MyConfigOptions>()
.Bind(Configuration.GetSection(MyConfigOptions.MyConfig))
.ValidateDataAnnotations();
services.AddControllersWithViews();
}
和消费者:
public HomeController(IOptions<MyConfigOptions> config,
ILogger<HomeController> logger)