Removing DefaultContentManagerSession

This commit is contained in:
Sebastien Ros
2014-08-27 12:09:18 -07:00
parent 7333d106a0
commit 262c825c26
22 changed files with 6 additions and 85 deletions

View File

@@ -33,7 +33,6 @@ 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);

View File

@@ -52,7 +52,6 @@ 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>();

View File

@@ -39,7 +39,6 @@ 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>();

View File

@@ -42,7 +42,6 @@ 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>();

View File

@@ -49,7 +49,6 @@ 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);

View File

@@ -70,11 +70,9 @@ 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>();

View File

@@ -58,7 +58,6 @@ 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);

View File

@@ -79,7 +79,6 @@ 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>();

View File

@@ -91,7 +91,6 @@ 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>();

View File

@@ -91,7 +91,6 @@ 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);

View File

@@ -51,7 +51,6 @@ 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" });

View File

@@ -63,7 +63,6 @@ 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"});

View File

@@ -49,7 +49,6 @@ 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" });

View File

@@ -53,7 +53,6 @@ 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" });

View File

@@ -53,7 +53,6 @@ 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>();

View File

@@ -41,7 +41,6 @@ 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>();

View File

@@ -48,7 +48,6 @@ 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>();

View File

@@ -31,7 +31,6 @@ 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;
@@ -50,7 +49,6 @@ namespace Orchard.ContentManagement {
IRepository<ContentItemVersionRecord> contentItemVersionRepository,
IContentDefinitionManager contentDefinitionManager,
ICacheManager cacheManager,
Func<IContentManagerSession> contentManagerSession,
Lazy<IContentDisplay> contentDisplay,
Lazy<ISessionLocator> sessionLocator,
Lazy<IEnumerable<IContentHandler>> handlers,
@@ -64,7 +62,6 @@ namespace Orchard.ContentManagement {
_contentItemVersionRepository = contentItemVersionRepository;
_contentDefinitionManager = contentDefinitionManager;
_cacheManager = cacheManager;
_contentManagerSession = contentManagerSession;
_identityResolverSelectors = identityResolverSelectors;
_sqlStatementProviders = sqlStatementProviders;
_shellSettings = shellSettings;
@@ -132,29 +129,14 @@ 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,
@@ -207,21 +189,10 @@ 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);
@@ -649,9 +620,8 @@ namespace Orchard.ContentManagement {
}
public void Clear() {
var session = _sessionLocator.Value.For(typeof(ContentItemRecord));
session.Clear();
_contentManagerSession().Clear();
//var session = _sessionLocator.Value.For(typeof(ContentItemRecord));
//session.Clear();
}
public IContentQuery<ContentItem> Query() {

View File

@@ -1,30 +0,0 @@
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();
}
}
}

View File

@@ -1,4 +1,6 @@
namespace Orchard.ContentManagement {
using System;
namespace Orchard.ContentManagement {
[Obsolete]
public interface IContentManagerSession : IDependency {
void Store(ContentItem item);
bool RecallVersionRecordId(int id, out ContentItem item);

View File

@@ -17,7 +17,7 @@ namespace Orchard.ContentManagement {
private readonly Dictionary<ContentIdentity, bool> _allIdentitiesForImportStatus; //For fast lookup of status
private readonly Queue<ContentIdentity> _dependencyIdentities;
private int _startIndex;
private int _batchSize = int.MaxValue;
private int _batchSize = 100;
private int _currentIndex;
public ImportContentSession(IContentManager contentManager) {

View File

@@ -382,9 +382,6 @@
<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>