Last active
December 25, 2015 14:39
-
-
Save Boggin/6992788 to your computer and use it in GitHub Desktop.
Ninject Configurer example [http://escapologist.wordpress.com/2013/10/15/ninject-configurer/]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Demo.Ldap.Configuration | |
{ | |
using Ninject.Configurer; | |
using Ninject.Modules; | |
public class LdapModule : NinjectModule | |
{ | |
public override void Load() | |
{ | |
this.Bind<LdapConfig>().ToConfigSection("demo/ldap"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Demo.Ldap | |
{ | |
public class LdapSearch : ILdapSearch | |
{ | |
public LdapSearch(LdapConfig config) | |
{ | |
this.Config = config; | |
this.Configuration = new LdapConfiguration(); | |
this.Configuration.ConfigureFactory(this.Config.DomainServer); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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