Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/Modules/Shell/ShellModuleInitializer.cs @ 5306

Last change on this file since 5306 was 4476, checked in by cfleisch, 14 years ago

Create repository (#1198)

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Microsoft.Practices.CompositeWeb;
5using Microsoft.Practices.CompositeWeb.Services;
6using Microsoft.Practices.CompositeWeb.Interfaces;
7using Microsoft.Practices.CompositeWeb.Configuration;
8using Microsoft.Practices.CompositeWeb.Authorization;
9using Microsoft.Practices.CompositeWeb.EnterpriseLibrary.Services;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.