diff --git a/src/SIL.LCModel/DomainImpl/FactoryAdditions.cs b/src/SIL.LCModel/DomainImpl/FactoryAdditions.cs
index 06482d00..11254e1b 100644
--- a/src/SIL.LCModel/DomainImpl/FactoryAdditions.cs
+++ b/src/SIL.LCModel/DomainImpl/FactoryAdditions.cs
@@ -2137,20 +2137,6 @@ private static void ParsePictureLoc(string s, ref PictureLocationRangeType locTy
return;
}
}
-
- ///
- /// Create a new entry with the given guid.
- ///
- public ICmPicture Create(Guid guid)
- {
- if (guid == Guid.Empty)
- return Create();
-
- int hvo = ((IDataReader) m_cache.ServiceLocator.GetInstance())
- .GetNextRealHvo();
- return new CmPicture(m_cache, hvo, guid);
- }
-
}
#endregion
diff --git a/src/SIL.LCModel/FactoryInterfaceAdditions.cs b/src/SIL.LCModel/FactoryInterfaceAdditions.cs
index 8c17ef97..7b55a56e 100644
--- a/src/SIL.LCModel/FactoryInterfaceAdditions.cs
+++ b/src/SIL.LCModel/FactoryInterfaceAdditions.cs
@@ -845,11 +845,6 @@ ICmPicture Create(string sFolder, int anchorLoc, IPictureLocationBridge location
ICmPicture Create(string sFolder, int anchorLoc, IPictureLocationBridge locationParser,
string sDescription, string srcFilename, string sLayoutPos, string sLocationRange,
string sCopyright, string sCaption, PictureLocationRangeType locRangeType, string sScaleFactor);
-
- ///
- /// Create a new entry with the given guid.
- ///
- ICmPicture Create(Guid guid);
}
///
diff --git a/src/SIL.LCModel/ILcmServiceLocator.cs b/src/SIL.LCModel/ILcmServiceLocator.cs
index 7f500c64..9d37345d 100644
--- a/src/SIL.LCModel/ILcmServiceLocator.cs
+++ b/src/SIL.LCModel/ILcmServiceLocator.cs
@@ -96,6 +96,7 @@ internal interface IServiceLocatorInternal
IdentityMap IdentityMap { get; }
LoadingServices LoadingServices { get; }
IUnitOfWorkService UnitOfWorkService { get; }
+ IDataReader DataReader { get; }
}
///
diff --git a/src/SIL.LCModel/IOC/LcmServiceLocatorFactory.cs b/src/SIL.LCModel/IOC/LcmServiceLocatorFactory.cs
index 97a61a27..f04fa79e 100644
--- a/src/SIL.LCModel/IOC/LcmServiceLocatorFactory.cs
+++ b/src/SIL.LCModel/IOC/LcmServiceLocatorFactory.cs
@@ -430,6 +430,14 @@ public IDataSetup DataSetup
}
}
+ public IDataReader DataReader
+ {
+ get
+ {
+ return GetInstance();
+ }
+ }
+
///
/// Get the specified object instance; short for getting ICmObjectRepository and asking it to GetObject.
///
diff --git a/src/SIL.LCModel/InterfaceDeclarations.cs b/src/SIL.LCModel/InterfaceDeclarations.cs
index 2ab68ecc..d974b172 100644
--- a/src/SIL.LCModel/InterfaceDeclarations.cs
+++ b/src/SIL.LCModel/InterfaceDeclarations.cs
@@ -638,6 +638,12 @@ public interface ILcmFactory where T : ICmObject
///
/// A new, unowned, ICmObject with a Guid, but no Hvo.
T Create();
+
+ ///
+ /// Basic creation method for an ICmObject with the given guid.
+ ///
+ /// A new, unowned, ICmObject with the given guid.
+ T Create(Guid guid);
}
#endregion
diff --git a/src/SIL.LCModel/LcmCache.cs b/src/SIL.LCModel/LcmCache.cs
index 7a427718..b6ed78d3 100644
--- a/src/SIL.LCModel/LcmCache.cs
+++ b/src/SIL.LCModel/LcmCache.cs
@@ -1085,6 +1085,11 @@ public ILcmServiceLocator ServiceLocator
get { return m_serviceLocator; }
}
+ internal IServiceLocatorInternal InternalServices
+ {
+ get { return (IServiceLocatorInternal) m_serviceLocator; }
+ }
+
///
/// Add to the list a ClassAndPropInfo for each concrete class of object that may be added to
/// property flid.
diff --git a/src/SIL.LCModel/LcmGenerate/factory.vm.cs b/src/SIL.LCModel/LcmGenerate/factory.vm.cs
index 3e6af2cb..21639ae4 100644
--- a/src/SIL.LCModel/LcmGenerate/factory.vm.cs
+++ b/src/SIL.LCModel/LcmGenerate/factory.vm.cs
@@ -10,6 +10,7 @@
## --------------------------------------------------------------------------------------------
#set( $className = $class.Name )
#set( $baseClassName = $class.BaseClass.Name )
+#set( $ownerStatus = $class.OwnerStatus )
#if ($class.Name == "LgWritingSystem")
#set( $classSfx = "FactoryLcm" )
#else
@@ -52,6 +53,25 @@ internal partial class ${className}$classSfx : I${className}$classSfx, ILcmFacto
((ICmObjectInternal)newby).InitializeNewOwnerlessCmObject(m_cache);
return newby;
}
+
+ ///
+ /// Basic creation method for an $className.
+ ///
+ /// A new, unowned, $className with the given guid.
+ public I$className Create(Guid guid)
+ {
+#if ($class.IsSingleton)
+ if (m_cache.ServiceLocator.GetInstance().Singleton != null)
+ throw new InvalidOperationException("Can not create more than one ${className}");
+#end
+ if (guid == Guid.Empty) guid = Guid.NewGuid();
+ int hvo = m_cache.InternalServices.DataReader.GetNextRealHvo();
+ var newby = new $className(m_cache, hvo, guid);
+#if ( $ownerStatus != "required")
+ ((ICmObjectInternal) newby).InitializeNewOwnerlessCmObjectWithPresetGuid();
+#end
+ return newby;
+ }
#end
///
diff --git a/tests/SIL.LCModel.Tests/Infrastructure/Impl/LexEntryTypeTests.cs b/tests/SIL.LCModel.Tests/Infrastructure/Impl/LexEntryTypeTests.cs
new file mode 100644
index 00000000..753bf3bf
--- /dev/null
+++ b/tests/SIL.LCModel.Tests/Infrastructure/Impl/LexEntryTypeTests.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq;
+using NUnit.Framework;
+
+namespace SIL.LCModel.Infrastructure.Impl
+{
+ public class LexEntryTypeTests: MemoryOnlyBackendProviderRestoredForEachTestTestBase
+ {
+ [Test]
+ public void CreateTypeWithGuid_CanAddToList()
+ {
+ var guid = Guid.NewGuid();
+ var lexEntryType = Cache.ServiceLocator.GetInstance().Create(guid);
+
+ Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS.Add(lexEntryType);
+
+ Assert.That(Cache.ServiceLocator.ObjectRepository.GetObject(guid), Is.EqualTo(lexEntryType));
+ }
+ }
+}
\ No newline at end of file