Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
namespace Demo.Ldap.Configuration
{
public LdapConfig(bool enabled, string user, string password, string domain)
{
this.Enabled = enabled;
this.User = user;
this.Password = password;
this.Domain = domain;
}
public bool Enabled { get; set; }
public string User { get; set; }
public string Password { get; set; }
public string Domain { get; set; }
}
namespace Demo.Ldap.Configuration
{
using Ninject.Configurer;
using Ninject.Modules;
public class LdapModule : NinjectModule
{
public override void Load()
{
this.Bind<LdapConfig>().ToConfigSection("demo/ldap");
}
}
}
namespace Demo.Ldap
{
public class LdapSearch : ILdapSearch
{
public LdapSearch(LdapConfig config)
{
this.Config = config;
this.Configuration = new LdapConfiguration();
this.Configuration.ConfigureFactory(this.Config.DomainServer);
}
}
}
namespace Demo.Ldap.Configuration
{
using System.Configuration;
public class LdapSection : ConfigurationSection
{
[ConfigurationProperty("enabled")]
public bool Enabled
{
get { return (bool)this["enabled"]; }
set { this["enabled"] = value; }
}
[ConfigurationProperty("user")]
public string User
{
get { return (string)this["user"]; }
set { this["user"] = value; }
}
[ConfigurationProperty("password")]
public string Password
{
get { return (string)this["password"]; }
set { this["password"] = value; }
}
[ConfigurationProperty("domain")]
public string Domain
{
get { return (string)this["domain"]; }
set { this["domain"] = value; }
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="demo">
<section name="ldap" type="Demo.Ldap.Configuration.LdapSection, Demo.Ldap, Culture=neutral" />
</sectionGroup>
...
<demo>
<ldap enabled="true" user="app-user" password="password" domain="fm" />
</demo>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment