[4476] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Text;
|
---|
| 4 | using Microsoft.Practices.CompositeWeb;
|
---|
| 5 | using Microsoft.Practices.CompositeWeb.Services;
|
---|
| 6 | using Microsoft.Practices.CompositeWeb.Interfaces;
|
---|
| 7 | using Microsoft.Practices.CompositeWeb.Configuration;
|
---|
| 8 | using Microsoft.Practices.CompositeWeb.Authorization;
|
---|
| 9 | using Microsoft.Practices.CompositeWeb.EnterpriseLibrary.Services;
|
---|
| 10 |
|
---|
| 11 | namespace OKB.Shell
|
---|
| 12 | {
|
---|
| 13 | public class ShellModuleInitializer : ModuleInitializer
|
---|
| 14 | {
|
---|
| 15 | private const string AuthorizationSection = "compositeWeb/authorization";
|
---|
| 16 |
|
---|
| 17 | public override void Load(CompositionContainer container)
|
---|
| 18 | {
|
---|
| 19 | base.Load(container);
|
---|
| 20 |
|
---|
| 21 | AddGlobalServices(container.Parent.Services);
|
---|
| 22 | AddModuleServices(container.Services);
|
---|
| 23 | RegisterSiteMapInformation(container.Services.Get<ISiteMapBuilderService>(true));
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | protected virtual void AddGlobalServices(IServiceCollection globalServices)
|
---|
| 27 | {
|
---|
| 28 | globalServices.AddNew<EnterpriseLibraryAuthorizationService, IAuthorizationService>();
|
---|
| 29 | globalServices.AddNew<SiteMapBuilderService, ISiteMapBuilderService>();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | protected virtual void AddModuleServices(IServiceCollection moduleServices)
|
---|
| 33 | {
|
---|
| 34 | // TODO: register services that can be accesed only by the Shell module
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)
|
---|
| 38 | {
|
---|
| 39 | SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Home", "~/Default.aspx", "Home", "Home");
|
---|
| 40 | siteMapBuilderService.AddNode(moduleNode);
|
---|
| 41 |
|
---|
| 42 | siteMapBuilderService.RootNode.Url = "~/Default.aspx";
|
---|
| 43 | siteMapBuilderService.RootNode.Title = "Optimization Knowledgebase";
|
---|
| 44 |
|
---|
| 45 | // TODO: register other site map nodes for pages that belong to the website root
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public override void Configure(IServiceCollection services, System.Configuration.Configuration moduleConfiguration)
|
---|
| 49 | {
|
---|
| 50 | IAuthorizationRulesService authorizationRuleService = services.Get<IAuthorizationRulesService>();
|
---|
| 51 | if (authorizationRuleService != null)
|
---|
| 52 | {
|
---|
| 53 | AuthorizationConfigurationSection authorizationSection = moduleConfiguration.GetSection(AuthorizationSection) as AuthorizationConfigurationSection;
|
---|
| 54 | if (authorizationSection != null)
|
---|
| 55 | {
|
---|
| 56 | foreach (AuthorizationRuleElement ruleElement in authorizationSection.ModuleRules)
|
---|
| 57 | {
|
---|
| 58 | authorizationRuleService.RegisterAuthorizationRule(ruleElement.AbsolutePath, ruleElement.RuleName);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | }
|
---|