Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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`**
```csharp

public 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);
```