mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
- SiteSettings interface/service and injection to support CurrentSite property in packages.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041140
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.Logging {
|
||||
public class CastleLogger : ILogger {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Logging {
|
||||
public enum LogLevel {
|
||||
|
||||
@@ -173,6 +173,9 @@
|
||||
<Compile Include="Security\Providers\FormsAuthenticationService.cs" />
|
||||
<Compile Include="Security\SecurityFilter.cs" />
|
||||
<Compile Include="Security\SecurityModule.cs" />
|
||||
<Compile Include="Settings\ISite.cs" />
|
||||
<Compile Include="Settings\ISiteService.cs" />
|
||||
<Compile Include="Settings\SettingsModule.cs" />
|
||||
<Compile Include="UI\Menus\AdminMenuFilter.cs" />
|
||||
<Compile Include="UI\Models\ModelTemplate.cs" />
|
||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||
|
||||
11
src/Orchard/Settings/ISite.cs
Normal file
11
src/Orchard/Settings/ISite.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Orchard.Models;
|
||||
|
||||
namespace Orchard.Settings {
|
||||
/// <summary>
|
||||
/// Interface provided by the "settings" model.
|
||||
/// </summary>
|
||||
public interface ISite : IModel {
|
||||
string SiteName { get; }
|
||||
string SuperUser { get; }
|
||||
}
|
||||
}
|
||||
5
src/Orchard/Settings/ISiteService.cs
Normal file
5
src/Orchard/Settings/ISiteService.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Orchard.Settings {
|
||||
public interface ISiteService : IDependency {
|
||||
ISite GetSiteSettings();
|
||||
}
|
||||
}
|
||||
24
src/Orchard/Settings/SettingsModule.cs
Normal file
24
src/Orchard/Settings/SettingsModule.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Module = Autofac.Builder.Module;
|
||||
|
||||
namespace Orchard.Settings {
|
||||
public class SettingsModule : Module {
|
||||
protected override void AttachToComponentRegistration(Autofac.IContainer container, Autofac.IComponentRegistration registration) {
|
||||
|
||||
var siteProperty = FindSiteProperty(registration.Descriptor.BestKnownImplementationType);
|
||||
|
||||
if (siteProperty != null) {
|
||||
registration.Activated += (sender, e) => {
|
||||
var siteService = e.Context.Resolve<ISiteService>();
|
||||
var currentSite = siteService.GetSiteSettings();
|
||||
siteProperty.SetValue(e.Instance, currentSite, null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo FindSiteProperty(Type type) {
|
||||
return type.GetProperty("CurrentSite", typeof(ISite));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user