Skip to content

Instantly share code, notes, and snippets.

@Boggin
Last active December 25, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Boggin/6992788 to your computer and use it in GitHub Desktop.
Save Boggin/6992788 to your computer and use it in GitHub Desktop.
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