Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bugthesystem/aspnet.mvc.configurationexporter
Makes server side configurations are available on client side
https://github.com/bugthesystem/aspnet.mvc.configurationexporter
c-sharp configuration javascript
Last synced: about 1 month ago
JSON representation
Makes server side configurations are available on client side
- Host: GitHub
- URL: https://github.com/bugthesystem/aspnet.mvc.configurationexporter
- Owner: bugthesystem
- License: mit
- Created: 2015-01-21T15:07:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-24T21:52:19.000Z (over 7 years ago)
- Last Synced: 2024-12-23T02:37:54.494Z (about 1 month ago)
- Topics: c-sharp, configuration, javascript
- Language: C#
- Homepage:
- Size: 899 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AspNet.Mvc.ConfigurationExporter
Provides server side configurations to available on client side[![Build status](https://ci.appveyor.com/api/projects/status/34tj2t4lf30ck7gt?svg=true)](https://ci.appveyor.com/project/ziyasal/aspnet-mvc-configurationexporter)
HOW TO USE
---------------------------To install AspNet.Mvc.ConfigurationExporter;
```
Install-Package AspNet.Mvc.ConfigurationExporter
```Register configuration exporter route;
```csharp
RouteTable.Routes.MapConfigExporter();
```Set configuration export mode;
**Mode: SECTION**
```xml
```
Add configuration section to web.config;
```xml
```Add configuration section values to web.config;
```xml
```
**Mode: KEYS**Add following settings to appSettings;
```xml
```### Export property values from custom types
**Suppose that we have a type and we'd like to make its properties available on client side which marked with `ConfigrExportable`**
```csharppublic interface ITestConfiguration
{
int TestInt { get; }
string TestString { get; }
int TestProperty { get; }
}public class TestConfiguration : ITestConfiguration
{
public int TestInt { get { return 20; } }[ConfigrExportable]
public string TestString { get { return "https://github.com/PanteonProject"; } }[ConfigrExportable(Name = "testName")]
public int TestProperty { get { return 10; } }}
```
Register type to exporter;```csharp
Exporter.Instance.RegisterType(type =>
DependencyResolver.Current.GetService(type));
//OR
Exporter.Instance.RegisterType(type =>
(ITestConfiguration)new TestConfiguration());
```Add following script tag to your page;
```html```
Access from js;
```js
console.log(window.configuration.AKey);
```
**Custom JS Namespace**Alternatively you can declare a namespace in App.config like this.
```xml
```
and access from js :
```js
console.log(github.config.AKey);
```