using System; using System.Collections.Generic; using System.Text; using Microsoft.Practices.CompositeWeb; using Microsoft.Practices.CompositeWeb.Interfaces; using Microsoft.Practices.CompositeWeb.Services; using Microsoft.Practices.CompositeWeb.Configuration; using Microsoft.Practices.CompositeWeb.EnterpriseLibrary.Services; namespace OKB.Administration { public class AdministrationModuleInitializer : ModuleInitializer { private const string AuthorizationSection = "compositeWeb/authorization"; public override void Load(CompositionContainer container) { base.Load(container); AddGlobalServices(container.Parent.Services); AddModuleServices(container.Services); RegisterSiteMapInformation(container.Services.Get(true)); container.RegisterTypeMapping(); } protected virtual void AddGlobalServices(IServiceCollection globalServices) { // TODO: add a service that will be visible to any module } protected virtual void AddModuleServices(IServiceCollection moduleServices) { // TODO: add a service that will be visible to this module } protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService) { SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Administration", "~/Administration/Default.aspx", "Administration"); siteMapBuilderService.AddNode(moduleNode); // TODO: register other site map nodes that Administration module might provide } public override void Configure(IServiceCollection services, System.Configuration.Configuration moduleConfiguration) { IAuthorizationRulesService authorizationRuleService = services.Get(); if (authorizationRuleService != null) { AuthorizationConfigurationSection authorizationSection = moduleConfiguration.GetSection(AuthorizationSection) as AuthorizationConfigurationSection; if (authorizationSection != null) { foreach (AuthorizationRuleElement ruleElement in authorizationSection.ModuleRules) { authorizationRuleService.RegisterAuthorizationRule(ruleElement.AbsolutePath, ruleElement.RuleName); } } } } } }