mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Revert "Removing DefaultContentManagerSession"
This reverts commit 262c825c26
.
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Orchard.Core.Tests.Body {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
|
@@ -52,6 +52,7 @@ namespace Orchard.Core.Tests.Common.Providers {
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<TestHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<CommonPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<CommonPartDriver>().As<IContentPartDriver>();
|
||||
|
@@ -39,6 +39,7 @@ namespace Orchard.Core.Tests.Scheduling {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
|
@@ -42,6 +42,7 @@ namespace Orchard.Core.Tests.Scheduling {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
|
@@ -49,6 +49,7 @@ namespace Orchard.Tests.Modules.Comments.Services {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
|
@@ -70,9 +70,11 @@ namespace Orchard.Tests.Modules.Indexing {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(_contentDefinitionManager.Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
|
@@ -58,6 +58,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>().InstancePerDependency();
|
||||
|
||||
builder.RegisterInstance(new Mock<IAuthenticationService>().Object);
|
||||
|
@@ -79,6 +79,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
|
@@ -91,6 +91,7 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
|
@@ -91,6 +91,7 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
|
@@ -51,6 +51,7 @@ namespace Orchard.Tests.ContentManagement {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
|
||||
|
@@ -63,6 +63,7 @@ namespace Orchard.Tests.ContentManagement {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(_contentDefinitionManager.Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterInstance(new ShellSettings {Name = ShellSettings.DefaultName, DataProvider = "SqlCe"});
|
||||
|
@@ -49,6 +49,7 @@ namespace Orchard.Tests.ContentManagement {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
|
||||
|
@@ -53,6 +53,7 @@ namespace Orchard.Tests.ContentManagement {
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
|
||||
|
@@ -53,6 +53,7 @@ namespace Orchard.Tests.Localization {
|
||||
builder.RegisterType<StubHttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TestCultureSelector>().As<ICultureSelector>();
|
||||
builder.RegisterType<DefaultCultureManager>().As<ICultureManager>();
|
||||
|
@@ -41,6 +41,7 @@ namespace Orchard.Projections.Tests.Services {
|
||||
|
||||
// ContentDefinitionManager
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
|
||||
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
|
@@ -48,6 +48,7 @@ namespace Orchard.Projections.Tests.Services {
|
||||
|
||||
// ContentDefinitionManager
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
|
||||
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
|
@@ -31,6 +31,7 @@ namespace Orchard.ContentManagement {
|
||||
private readonly IRepository<ContentItemVersionRecord> _contentItemVersionRepository;
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
private readonly Func<IContentManagerSession> _contentManagerSession;
|
||||
private readonly Lazy<IContentDisplay> _contentDisplay;
|
||||
private readonly Lazy<ISessionLocator> _sessionLocator;
|
||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||
@@ -49,6 +50,7 @@ namespace Orchard.ContentManagement {
|
||||
IRepository<ContentItemVersionRecord> contentItemVersionRepository,
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
ICacheManager cacheManager,
|
||||
Func<IContentManagerSession> contentManagerSession,
|
||||
Lazy<IContentDisplay> contentDisplay,
|
||||
Lazy<ISessionLocator> sessionLocator,
|
||||
Lazy<IEnumerable<IContentHandler>> handlers,
|
||||
@@ -62,6 +64,7 @@ namespace Orchard.ContentManagement {
|
||||
_contentItemVersionRepository = contentItemVersionRepository;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_cacheManager = cacheManager;
|
||||
_contentManagerSession = contentManagerSession;
|
||||
_identityResolverSelectors = identityResolverSelectors;
|
||||
_sqlStatementProviders = sqlStatementProviders;
|
||||
_shellSettings = shellSettings;
|
||||
@@ -129,14 +132,29 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public virtual ContentItem Get(int id, VersionOptions options, QueryHints hints) {
|
||||
var session = _contentManagerSession();
|
||||
ContentItem contentItem;
|
||||
|
||||
ContentItemVersionRecord versionRecord = null;
|
||||
|
||||
// obtain the root records based on version options
|
||||
if (options.VersionRecordId != 0) {
|
||||
// short-circuit if item held in session
|
||||
if (session.RecallVersionRecordId(options.VersionRecordId, out contentItem)) {
|
||||
return contentItem;
|
||||
}
|
||||
|
||||
versionRecord = _contentItemVersionRepository.Get(options.VersionRecordId);
|
||||
}
|
||||
else if (session.RecallContentRecordId(id, out contentItem)) {
|
||||
// try to reload a previously loaded published content item
|
||||
|
||||
if (options.IsPublished) {
|
||||
return contentItem;
|
||||
}
|
||||
|
||||
versionRecord = contentItem.VersionRecord;
|
||||
}
|
||||
else {
|
||||
// do a query to load the records in case Get is called directly
|
||||
var contentItemVersionRecords = GetManyImplementation(hints,
|
||||
@@ -189,10 +207,21 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
}
|
||||
|
||||
// return item if obtained earlier in session
|
||||
if (session.RecallVersionRecordId(versionRecord.Id, out contentItem)) {
|
||||
if (options.IsDraftRequired && versionRecord.Published) {
|
||||
return BuildNewVersion(contentItem);
|
||||
}
|
||||
return contentItem;
|
||||
}
|
||||
|
||||
// allocate instance and set record property
|
||||
contentItem = New(versionRecord.ContentItemRecord.ContentType.Name);
|
||||
contentItem.VersionRecord = versionRecord;
|
||||
|
||||
// store in session prior to loading to avoid some problems with simple circular dependencies
|
||||
session.Store(contentItem);
|
||||
|
||||
// create a context with a new instance to load
|
||||
var context = new LoadContentContext(contentItem);
|
||||
|
||||
@@ -620,8 +649,9 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
//var session = _sessionLocator.Value.For(typeof(ContentItemRecord));
|
||||
//session.Clear();
|
||||
var session = _sessionLocator.Value.For(typeof(ContentItemRecord));
|
||||
session.Clear();
|
||||
_contentManagerSession().Clear();
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> Query() {
|
||||
|
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
public class DefaultContentManagerSession : IContentManagerSession {
|
||||
private readonly IDictionary<int, ContentItem> _itemByVersionRecordId = new Dictionary<int, ContentItem>();
|
||||
private readonly IDictionary<int, ContentItem> _publishedItemsByContentRecordId = new Dictionary<int, ContentItem>();
|
||||
|
||||
public void Store(ContentItem item) {
|
||||
_itemByVersionRecordId.Add(item.VersionRecord.Id, item);
|
||||
|
||||
// is it the Published version ?
|
||||
if (item.VersionRecord.Latest && item.VersionRecord.Published) {
|
||||
_publishedItemsByContentRecordId[item.Id] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RecallVersionRecordId(int id, out ContentItem item) {
|
||||
return _itemByVersionRecordId.TryGetValue(id, out item);
|
||||
}
|
||||
|
||||
public bool RecallContentRecordId(int id, out ContentItem item) {
|
||||
return _publishedItemsByContentRecordId.TryGetValue(id, out item);
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_itemByVersionRecordId.Clear();
|
||||
_publishedItemsByContentRecordId.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
namespace Orchard.ContentManagement {
|
||||
[Obsolete]
|
||||
namespace Orchard.ContentManagement {
|
||||
public interface IContentManagerSession : IDependency {
|
||||
void Store(ContentItem item);
|
||||
bool RecallVersionRecordId(int id, out ContentItem item);
|
||||
|
@@ -382,6 +382,9 @@
|
||||
<Compile Include="ContentManagement\DefaultContentManager.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DefaultContentManagerSession.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DefaultContentQuery.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
Reference in New Issue
Block a user