From 56c04fced822cbf8c5af000ebd7eb41aa7fdda9b Mon Sep 17 00:00:00 2001
From: Anton Piccardo-Selg <anton.piccardo-selg@tessella.com>
Date: Tue, 7 Jun 2016 08:43:25 +0100
Subject: [PATCH] Refs #15283 Create template declaraions for Singletons

---
 Framework/API/CMakeLists.txt                  |  1 +
 .../API/inc/MantidAPI/AlgorithmFactory.h      | 14 ++++++-------
 .../API/inc/MantidAPI/AnalysisDataService.h   | 15 +++++++-------
 .../API/inc/MantidAPI/ArchiveSearchFactory.h  | 14 ++++++-------
 Framework/API/inc/MantidAPI/CatalogFactory.h  | 13 ++++++------
 Framework/API/inc/MantidAPI/CatalogManager.h  |  9 ++++++---
 Framework/API/inc/MantidAPI/ColumnFactory.h   | 13 ++++++------
 .../API/inc/MantidAPI/ConstraintFactory.h     | 13 ++++++------
 .../API/inc/MantidAPI/CostFunctionFactory.h   | 14 ++++++-------
 Framework/API/inc/MantidAPI/DllConfig.h       |  2 ++
 .../API/inc/MantidAPI/DomainCreatorFactory.h  | 14 ++++++-------
 Framework/API/inc/MantidAPI/FileFinder.h      | 13 ++++++------
 .../API/inc/MantidAPI/FileLoaderRegistry.h    | 15 ++++++--------
 .../API/inc/MantidAPI/FrameworkManager.h      | 13 ++++++------
 .../API/inc/MantidAPI/FuncMinimizerFactory.h  | 13 ++++++------
 Framework/API/inc/MantidAPI/FunctionFactory.h | 13 ++++++------
 .../inc/MantidAPI/ImplicitFunctionFactory.h   | 15 +++++++-------
 .../ImplicitFunctionParameterParserFactory.h  | 16 +++++++--------
 .../MantidAPI/ImplicitFunctionParserFactory.h | 15 +++++++-------
 .../API/inc/MantidAPI/InstrumentDataService.h | 16 +++++++--------
 .../inc/MantidAPI/RemoteJobManagerFactory.h   | 15 +++++++-------
 .../inc/MantidAPI/ScriptRepositoryFactory.h   | 15 +++++++-------
 .../API/inc/MantidAPI/TransformScaleFactory.h | 15 +++++++-------
 .../API/inc/MantidAPI/WorkspaceFactory.h      | 16 +++++++--------
 Framework/API/src/AlgorithmFactory.cpp        |  7 +++++++
 Framework/API/src/AnalysisDataService.cpp     |  6 ++++++
 Framework/API/src/ArchiveSearchFactory.cpp    |  7 ++++++-
 Framework/API/src/CatalogFactory.cpp          |  7 +++++++
 Framework/API/src/CatalogManager.cpp          |  7 +++++++
 Framework/API/src/ColumnFactory.cpp           |  6 ++++++
 Framework/API/src/ConstraintFactory.cpp       |  6 ++++++
 Framework/API/src/CostFunctionFactory.cpp     |  6 ++++++
 Framework/API/src/DomainCreatorFactory.cpp    |  6 ++++++
 Framework/API/src/FileFinder.cpp              |  6 ++++++
 Framework/API/src/FileLoaderRegistry.cpp      |  6 ++++++
 Framework/API/src/FrameworkManager.cpp        |  6 ++++++
 Framework/API/src/FuncMinimizerFactory.cpp    |  6 ++++++
 Framework/API/src/FunctionFactory.cpp         |  6 ++++++
 Framework/API/src/ImplicitFunctionFactory.cpp |  7 +++++++
 ...ImplicitFunctionParameterParserFactory.cpp |  7 +++++++
 .../API/src/ImplicitFunctionParserFactory.cpp |  7 +++++++
 Framework/API/src/InstrumentDataService.cpp   |  7 +++++++
 Framework/API/src/RemoteJobManagerFactory.cpp |  6 ++++++
 Framework/API/src/ScriptRepositoryFactory.cpp |  6 ++++++
 Framework/API/src/TransformScaleFactory.cpp   |  7 +++++++
 Framework/API/src/WorkspaceFactory.cpp        |  6 ++++++
 .../Kernel/inc/MantidKernel/ConfigService.h   |  8 +-------
 Framework/Kernel/inc/MantidKernel/DllConfig.h |  2 ++
 .../Kernel/inc/MantidKernel/LibraryManager.h  |  9 ++-------
 .../MantidKernel/PropertyManagerDataService.h | 10 ++--------
 .../Kernel/inc/MantidKernel/UsageService.h    |  8 ++------
 Framework/Kernel/src/ConfigService.cpp        |  4 ++++
 Framework/Kernel/src/LibraryManager.cpp       |  2 ++
 .../Kernel/src/PropertyManagerDataService.cpp |  2 ++
 Framework/Kernel/src/UsageService.cpp         |  1 +
 .../inc/MantidMDAlgorithms/DllConfig.h        |  2 ++
 .../Quantification/ForegroundModelFactory.h   | 14 ++++++-------
 .../MDResolutionConvolutionFactory.h          | 14 ++++++-------
 .../Quantification/ForegroundModelFactory.cpp |  7 +++++++
 .../MDResolutionConvolutionFactory.cpp        |  7 +++++++
 .../inc/MantidQtAPI/AlgorithmInputHistory.h   | 12 +++++------
 MantidQt/API/inc/MantidQtAPI/DllOption.h      |  2 ++
 .../API/inc/MantidQtAPI/InterfaceFactory.h    | 20 +++++++++----------
 .../SelectionNotificationService.h            | 12 +++++------
 MantidQt/API/src/AlgorithmInputHistory.cpp    |  2 ++
 MantidQt/API/src/InterfaceFactory.cpp         |  3 ++-
 .../API/src/SelectionNotificationService.cpp  |  2 +-
 67 files changed, 365 insertions(+), 231 deletions(-)
 create mode 100644 Framework/API/src/CatalogFactory.cpp

diff --git a/Framework/API/CMakeLists.txt b/Framework/API/CMakeLists.txt
index de884455501..3199f5d6a4e 100644
--- a/Framework/API/CMakeLists.txt
+++ b/Framework/API/CMakeLists.txt
@@ -12,6 +12,7 @@ set ( SRC_FILES
 	src/Axis.cpp
 	src/BinEdgeAxis.cpp
 	src/BoxController.cpp
+        src/CatalogFactory.cpp
 	src/CatalogManager.cpp
 	src/CatalogSession.cpp
 	src/ChopperModel.cpp
diff --git a/Framework/API/inc/MantidAPI/AlgorithmFactory.h b/Framework/API/inc/MantidAPI/AlgorithmFactory.h
index 3869d01863a..37c18ad440f 100644
--- a/Framework/API/inc/MantidAPI/AlgorithmFactory.h
+++ b/Framework/API/inc/MantidAPI/AlgorithmFactory.h
@@ -168,14 +168,6 @@ private:
   VersionMap m_vmap;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>;
-#endif /* _WIN32 */
-
 typedef Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>
     AlgorithmFactory;
 
@@ -188,4 +180,10 @@ typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmFactoryImpl>;
+}
+}
+
 #endif /*MANTID_API_ALGORITHMFACTORY_H_*/
diff --git a/Framework/API/inc/MantidAPI/AnalysisDataService.h b/Framework/API/inc/MantidAPI/AnalysisDataService.h
index d56ddcef2bd..e9bf588fd3d 100644
--- a/Framework/API/inc/MantidAPI/AnalysisDataService.h
+++ b/Framework/API/inc/MantidAPI/AnalysisDataService.h
@@ -178,14 +178,7 @@ private:
   std::string m_illegalChars;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AnalysisDataServiceImpl (needed for dllexport/dllimport) and a typedef for
-/// it.
-#ifdef _WIN32
-// this breaks new namespace declaration rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<AnalysisDataServiceImpl>;
-#endif /* _WIN32 */
+
 typedef Mantid::Kernel::SingletonHolder<AnalysisDataServiceImpl>
     AnalysisDataService;
 
@@ -249,4 +242,10 @@ typedef const Poco::AutoPtr<AnalysisDataServiceImpl::GroupUpdatedNotification> &
 } // Namespace API
 } // Namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::AnalysisDataServiceImpl>;
+}
+}
+
 #endif /*MANTID_KERNEL_ANALYSISDATASERVICE_H_*/
diff --git a/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h b/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h
index 875d6950d14..98855c2622f 100644
--- a/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h
+++ b/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h
@@ -56,17 +56,15 @@ private:
   ~ArchiveSearchFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ArchiveSearchFactoryImpl>;
-#endif /* _WIN32 */
-
 typedef Mantid::Kernel::SingletonHolder<ArchiveSearchFactoryImpl>
     ArchiveSearchFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::ArchiveSearchFactoryImpl>;
+}
+}
+
 #endif // MANTID_API_ARCHIVESEARCHFACTORY_H_
diff --git a/Framework/API/inc/MantidAPI/CatalogFactory.h b/Framework/API/inc/MantidAPI/CatalogFactory.h
index dc09ed9e263..1bc7a885f9d 100644
--- a/Framework/API/inc/MantidAPI/CatalogFactory.h
+++ b/Framework/API/inc/MantidAPI/CatalogFactory.h
@@ -76,13 +76,6 @@ private:
   mutable std::map<std::string, boost::shared_ptr<ICatalog>> m_createdCatalogs;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// CatalogFactoryImpl (needed for dllexport/dllimport) .
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<CatalogFactoryImpl>;
-#endif /* _WIN32 */
 /// The specialisation of the SingletonHolder class that holds the
 /// CatalogFactory
 typedef Mantid::Kernel::SingletonHolder<CatalogFactoryImpl>
@@ -91,4 +84,10 @@ typedef Mantid::Kernel::SingletonHolder<CatalogFactoryImpl>
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::CatalogFactoryImpl>;
+}
+}
+
 #endif /*MANTID_API_CATALOGFACTORYIMPL_H_*/
diff --git a/Framework/API/inc/MantidAPI/CatalogManager.h b/Framework/API/inc/MantidAPI/CatalogManager.h
index 05b65ebc794..f528e2fd4a5 100644
--- a/Framework/API/inc/MantidAPI/CatalogManager.h
+++ b/Framework/API/inc/MantidAPI/CatalogManager.h
@@ -67,11 +67,14 @@ private:
   std::map<CatalogSession_sptr, ICatalog_sptr> m_activeCatalogs;
 };
 
-#ifdef _WIN32
-template class MANTID_API_DLL Kernel::SingletonHolder<CatalogManagerImpl>;
-#endif
 typedef Kernel::SingletonHolder<CatalogManagerImpl>
     CatalogManager;
 }
 }
+
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Kernel::SingletonHolder<Mantid::API::CatalogManagerImpl>;
+}
+}
 #endif /* MANTID_ICAT_CATALOGMANAGERIMPL_H_ */
diff --git a/Framework/API/inc/MantidAPI/ColumnFactory.h b/Framework/API/inc/MantidAPI/ColumnFactory.h
index e17431b2d12..2db50e7ca76 100644
--- a/Framework/API/inc/MantidAPI/ColumnFactory.h
+++ b/Framework/API/inc/MantidAPI/ColumnFactory.h
@@ -63,17 +63,16 @@ private:
   ~ColumnFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ColumnFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<ColumnFactoryImpl>
     ColumnFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::ColumnFactoryImpl>;
+}
+}
+
 #endif /*MANTID_API_COLUMNFACTORY_H_*/
diff --git a/Framework/API/inc/MantidAPI/ConstraintFactory.h b/Framework/API/inc/MantidAPI/ConstraintFactory.h
index 1d18787c26e..a4f210fdf7b 100644
--- a/Framework/API/inc/MantidAPI/ConstraintFactory.h
+++ b/Framework/API/inc/MantidAPI/ConstraintFactory.h
@@ -72,19 +72,18 @@ private:
   ~ConstraintFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ConstraintFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<ConstraintFactoryImpl>
     ConstraintFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::ConstraintFactoryImpl>;
+}
+}
+
 /**
  * Macro for declaring a new type of function to be used with the
  * FunctionFactory
diff --git a/Framework/API/inc/MantidAPI/CostFunctionFactory.h b/Framework/API/inc/MantidAPI/CostFunctionFactory.h
index b18865e0406..c1717e0b365 100644
--- a/Framework/API/inc/MantidAPI/CostFunctionFactory.h
+++ b/Framework/API/inc/MantidAPI/CostFunctionFactory.h
@@ -63,17 +63,17 @@ private:
   CostFunctionFactoryImpl();
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<CostFunctionFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<CostFunctionFactoryImpl>
     CostFunctionFactory;
 
 } // namespace API
 } // namespace Mantid
 
+
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::CostFunctionFactoryImpl>;
+}
+}
+
 #endif /*MANTID_API_COSTFUNCTIONFACTORY_H_*/
diff --git a/Framework/API/inc/MantidAPI/DllConfig.h b/Framework/API/inc/MantidAPI/DllConfig.h
index ff00439cca8..c335cb665f6 100644
--- a/Framework/API/inc/MantidAPI/DllConfig.h
+++ b/Framework/API/inc/MantidAPI/DllConfig.h
@@ -32,8 +32,10 @@
 
 #ifdef IN_MANTID_API
 #define MANTID_API_DLL DLLExport
+#define EXTERN_MANTID_API extern
 #else
 #define MANTID_API_DLL DLLImport
+#define EXTERN_MANTID_API extern
 #endif /* IN_MANTID_API*/
 
 #endif // MANTID_API_DLLCONFIG_H_
diff --git a/Framework/API/inc/MantidAPI/DomainCreatorFactory.h b/Framework/API/inc/MantidAPI/DomainCreatorFactory.h
index 6cb63eaaa71..b778a757709 100644
--- a/Framework/API/inc/MantidAPI/DomainCreatorFactory.h
+++ b/Framework/API/inc/MantidAPI/DomainCreatorFactory.h
@@ -68,18 +68,16 @@ private:
   using Kernel::DynamicFactory<IDomainCreator>::createUnwrapped;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// DomainCreatorFactoryImpl (needed for dllexport/dllimport) and a typedef for
-/// it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<DomainCreatorFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<DomainCreatorFactoryImpl>
     DomainCreatorFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::DomainCreatorFactoryImpl>;
+}
+}
+
 #endif /* MANTID_API_DOMAINCREATORFACTORY_H_ */
diff --git a/Framework/API/inc/MantidAPI/FileFinder.h b/Framework/API/inc/MantidAPI/FileFinder.h
index 80956529005..92ef7c19cfc 100644
--- a/Framework/API/inc/MantidAPI/FileFinder.h
+++ b/Framework/API/inc/MantidAPI/FileFinder.h
@@ -94,16 +94,15 @@ private:
   int m_globOption;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileFinderImpl>;
-#endif /* _WIN32 */
-
 typedef Mantid::Kernel::SingletonHolder<FileFinderImpl>
     FileFinder;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FileFinderImpl>;
+}
+}
+
 #endif // MANTID_API_FILEFINDER_H_
diff --git a/Framework/API/inc/MantidAPI/FileLoaderRegistry.h b/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
index 18a300ac9f9..c3e3bf2f16f 100644
--- a/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
+++ b/Framework/API/inc/MantidAPI/FileLoaderRegistry.h
@@ -144,15 +144,6 @@ private:
   mutable Kernel::Logger m_log;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// FileLoaderRegistryImpl (needed for dllexport/dllimport) and a typedef for
-/// it.
-#ifdef _WIN32
-// this breaks new namespace declaration rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>;
-#endif /* _WIN32 */
-
 /// Type for the actual singleton instance
 typedef Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>
     FileLoaderRegistry;
@@ -160,4 +151,10 @@ typedef Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>;
+}
+}
+
 #endif /* MANTID_API_FILELOADERREGISTRY_H_ */
diff --git a/Framework/API/inc/MantidAPI/FrameworkManager.h b/Framework/API/inc/MantidAPI/FrameworkManager.h
index 2053bfa9750..90383b3f0ed 100644
--- a/Framework/API/inc/MantidAPI/FrameworkManager.h
+++ b/Framework/API/inc/MantidAPI/FrameworkManager.h
@@ -135,17 +135,16 @@ private:
 #endif
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaration rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<FrameworkManagerImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<FrameworkManagerImpl>
     FrameworkManager;
 
 } // namespace Kernel
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FrameworkManagerImpl>;
+}
+}
+
 #endif /*MANTID_API_FRAMEWORKMANAGER_H_*/
diff --git a/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h b/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h
index 850ce1c40d9..a8466107519 100644
--- a/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h
+++ b/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h
@@ -61,19 +61,18 @@ private:
   FuncMinimizerFactoryImpl();
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<FuncMinimizerFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<FuncMinimizerFactoryImpl>
     FuncMinimizerFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FuncMinimizerFactoryImpl>;
+}
+}
+
 /**
  * Macro for declaring a new type of minimizers to be used with the
  * FuncMinimizerFactory
diff --git a/Framework/API/inc/MantidAPI/FunctionFactory.h b/Framework/API/inc/MantidAPI/FunctionFactory.h
index 0b708712df1..b9e8c214a39 100644
--- a/Framework/API/inc/MantidAPI/FunctionFactory.h
+++ b/Framework/API/inc/MantidAPI/FunctionFactory.h
@@ -142,13 +142,6 @@ const std::vector<std::string> &FunctionFactoryImpl::getFunctionNames() const {
   return typeNames;
 }
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<FunctionFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<FunctionFactoryImpl>
     FunctionFactory;
 
@@ -161,6 +154,12 @@ typedef const Poco::AutoPtr<FunctionFactoryUpdateNotification> &
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FunctionFactoryImpl>;
+}
+}
+
 /**
  * Macro for declaring a new type of function to be used with the
  * FunctionFactory
diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h
index 55e0fa2f193..69196e90c4f 100644
--- a/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h
+++ b/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h
@@ -64,18 +64,17 @@ private:
   ~ImplicitFunctionFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef
-/// for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ImplicitFunctionFactoryImpl>;
-#endif /* _WIN32 */
 
 typedef Mantid::Kernel::SingletonHolder<
     ImplicitFunctionFactoryImpl> ImplicitFunctionFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionFactoryImpl>;
+}
+}
+
+
 #endif
diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h
index 07bfe824373..25096efc9bc 100644
--- a/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h
+++ b/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h
@@ -62,18 +62,16 @@ private:
   ~ImplicitFunctionParameterParserFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef
-/// for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ImplicitFunctionParameterParserFactoryImpl>;
-#endif /* _WIN32 */
-
 typedef Mantid::Kernel::SingletonHolder<ImplicitFunctionParameterParserFactoryImpl>
         ImplicitFunctionParameterParserFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionParameterParserFactoryImpl>;
+}
+}
+
 #endif
diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h
index 8da39a8f65f..b4953ccd771 100644
--- a/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h
+++ b/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h
@@ -66,18 +66,17 @@ private:
   ~ImplicitFunctionParserFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef
-/// for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ImplicitFunctionParserFactoryImpl>;
-#endif /* _WIN32 */
 
 typedef Mantid::Kernel::SingletonHolder<
     ImplicitFunctionParserFactoryImpl> ImplicitFunctionParserFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionParserFactoryImpl>;
+}
+}
+
 #endif
diff --git a/Framework/API/inc/MantidAPI/InstrumentDataService.h b/Framework/API/inc/MantidAPI/InstrumentDataService.h
index 5c7040c63ee..79304263a45 100644
--- a/Framework/API/inc/MantidAPI/InstrumentDataService.h
+++ b/Framework/API/inc/MantidAPI/InstrumentDataService.h
@@ -48,17 +48,17 @@ private:
   operator=(const InstrumentDataServiceImpl &) = delete;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AnalysisDataServiceImpl (needed for dllexport/dllimport) and a typedef for
-/// it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<InstrumentDataServiceImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<
     InstrumentDataServiceImpl> InstrumentDataService;
 
 } // Namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::InstrumentDataServiceImpl>;
+}
+}
+
 #endif /*INSTRUMENTDATASERVICE_*/
diff --git a/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h b/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h
index 8718622b4fe..05321c94a9a 100644
--- a/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h
+++ b/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h
@@ -86,14 +86,6 @@ private:
   using Kernel::DynamicFactory<IRemoteJobManager>::create;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// RemoteJobManagerFactoryImpl (needed for dllexport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<RemoteJobManagerFactoryImpl>;
-#endif /* _WIN32 */
-
 // The factory is just a specialisation of SingletonHolder
 typedef Mantid::Kernel::SingletonHolder<
     RemoteJobManagerFactoryImpl> RemoteJobManagerFactory;
@@ -101,6 +93,13 @@ typedef Mantid::Kernel::SingletonHolder<
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::RemoteJobManagerFactoryImpl>;
+}
+}
+
 /* Macro to register (remote job manager) classes into the factory. As
  * with the equivalent macros of the workspace factory or the
  * algorithm factory, this creates a global object in an anonymous
diff --git a/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h b/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h
index e8d098323f3..a9db437db5f 100644
--- a/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h
+++ b/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h
@@ -67,19 +67,20 @@ private:
   ~ScriptRepositoryFactoryImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<ScriptRepositoryFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<
     ScriptRepositoryFactoryImpl> ScriptRepositoryFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::ScriptRepositoryFactoryImpl>;
+}
+}
+
+
 /**
  * Macro for declaring a new type of function to be used with the
  * FunctionFactory
diff --git a/Framework/API/inc/MantidAPI/TransformScaleFactory.h b/Framework/API/inc/MantidAPI/TransformScaleFactory.h
index d7913f74653..c1f715acbd3 100644
--- a/Framework/API/inc/MantidAPI/TransformScaleFactory.h
+++ b/Framework/API/inc/MantidAPI/TransformScaleFactory.h
@@ -67,18 +67,17 @@ private:
   // Do not use default methods
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// TransformScaleFactoryImpl (needed for dllexport/dllimport) and a typedef for
-/// it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<TransformScaleFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<
     TransformScaleFactoryImpl> TransformScaleFactory;
 
 } // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::TransformScaleFactoryImpl>;
+}
+}
+
 #endif /* MANTID_API_TRANSFORMSCALEFACTORY_H_ */
diff --git a/Framework/API/inc/MantidAPI/WorkspaceFactory.h b/Framework/API/inc/MantidAPI/WorkspaceFactory.h
index 3dc53497f9a..a89c5720aba 100644
--- a/Framework/API/inc/MantidAPI/WorkspaceFactory.h
+++ b/Framework/API/inc/MantidAPI/WorkspaceFactory.h
@@ -98,17 +98,17 @@ private:
   using Kernel::DynamicFactory<Workspace>::create;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_API_DLL
-    Mantid::Kernel::SingletonHolder<WorkspaceFactoryImpl>;
-#endif /* _WIN32 */
 typedef Mantid::Kernel::SingletonHolder<WorkspaceFactoryImpl>
     WorkspaceFactory;
 
-} // namespace Kernel
+} // namespace API
 } // namespace Mantid
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_API template class MANTID_API_DLL
+      Mantid::Kernel::SingletonHolder<Mantid::API::WorkspaceFactoryImpl>;
+}
+}
+
 #endif /*MANTID_KERNEL_WORKSPACEFACTORY_H_*/
diff --git a/Framework/API/src/AlgorithmFactory.cpp b/Framework/API/src/AlgorithmFactory.cpp
index 3401322948f..a5234ba34e0 100644
--- a/Framework/API/src/AlgorithmFactory.cpp
+++ b/Framework/API/src/AlgorithmFactory.cpp
@@ -426,5 +426,12 @@ AlgorithmFactoryImpl::createAlgorithm(const std::string &name,
   return Kernel::DynamicFactory<Algorithm>::create(createName(name, version));
 }
 
+
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/AnalysisDataService.cpp b/Framework/API/src/AnalysisDataService.cpp
index 44f38d03114..d7a7d7d0083 100644
--- a/Framework/API/src/AnalysisDataService.cpp
+++ b/Framework/API/src/AnalysisDataService.cpp
@@ -325,3 +325,9 @@ void AnalysisDataServiceImpl::verifyName(const std::string &name) {
 
 } // Namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::AnalysisDataServiceImpl>;
+}
+}
diff --git a/Framework/API/src/ArchiveSearchFactory.cpp b/Framework/API/src/ArchiveSearchFactory.cpp
index c05b3aa0aef..36d22ab9fef 100644
--- a/Framework/API/src/ArchiveSearchFactory.cpp
+++ b/Framework/API/src/ArchiveSearchFactory.cpp
@@ -8,6 +8,11 @@ namespace API {
 
 /// Default constructor
 ArchiveSearchFactoryImpl::ArchiveSearchFactoryImpl() {}
-
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::ArchiveSearchFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/CatalogFactory.cpp b/Framework/API/src/CatalogFactory.cpp
new file mode 100644
index 00000000000..59d64552390
--- /dev/null
+++ b/Framework/API/src/CatalogFactory.cpp
@@ -0,0 +1,7 @@
+#include "MantidAPI/CatalogFactory.h"
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::CatalogFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/CatalogManager.cpp b/Framework/API/src/CatalogManager.cpp
index ec7babcff5f..47816044bde 100644
--- a/Framework/API/src/CatalogManager.cpp
+++ b/Framework/API/src/CatalogManager.cpp
@@ -108,5 +108,12 @@ std::vector<CatalogSession_sptr> CatalogManagerImpl::getActiveSessions() {
 size_t CatalogManagerImpl::numberActiveSessions() const {
   return m_activeCatalogs.size();
 }
+
+}
+}
+
+namespace Mantid {
+namespace Kernel {
+  template class Kernel::SingletonHolder<Mantid::API::CatalogManagerImpl>;
 }
 }
diff --git a/Framework/API/src/ColumnFactory.cpp b/Framework/API/src/ColumnFactory.cpp
index 64b4617d82c..964aef33fd6 100644
--- a/Framework/API/src/ColumnFactory.cpp
+++ b/Framework/API/src/ColumnFactory.cpp
@@ -14,3 +14,9 @@ ColumnFactoryImpl::create(const std::string &type) const {
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::ColumnFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/ConstraintFactory.cpp b/Framework/API/src/ConstraintFactory.cpp
index cf46f18d2fb..fbda1f32c5e 100644
--- a/Framework/API/src/ConstraintFactory.cpp
+++ b/Framework/API/src/ConstraintFactory.cpp
@@ -53,3 +53,9 @@ IConstraint *ConstraintFactoryImpl::createInitialized(IFunction *fun,
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::ConstraintFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/CostFunctionFactory.cpp b/Framework/API/src/CostFunctionFactory.cpp
index ea0e131e3a0..bb454a716a3 100644
--- a/Framework/API/src/CostFunctionFactory.cpp
+++ b/Framework/API/src/CostFunctionFactory.cpp
@@ -15,3 +15,9 @@ CostFunctionFactoryImpl::CostFunctionFactoryImpl()
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::CostFunctionFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/DomainCreatorFactory.cpp b/Framework/API/src/DomainCreatorFactory.cpp
index d9f492610cd..b0f6f8acca0 100644
--- a/Framework/API/src/DomainCreatorFactory.cpp
+++ b/Framework/API/src/DomainCreatorFactory.cpp
@@ -26,3 +26,9 @@ IDomainCreator *DomainCreatorFactoryImpl::createDomainCreator(
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::DomainCreatorFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/FileFinder.cpp b/Framework/API/src/FileFinder.cpp
index f271ee799f5..7aeb6e0d621 100644
--- a/Framework/API/src/FileFinder.cpp
+++ b/Framework/API/src/FileFinder.cpp
@@ -785,3 +785,9 @@ std::string FileFinderImpl::toUpper(const std::string &src) const {
 
 } // API
 } // Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::FileFinderImpl>;
+}
+}
diff --git a/Framework/API/src/FileLoaderRegistry.cpp b/Framework/API/src/FileLoaderRegistry.cpp
index 5f8befb87fb..0315f994616 100644
--- a/Framework/API/src/FileLoaderRegistry.cpp
+++ b/Framework/API/src/FileLoaderRegistry.cpp
@@ -201,3 +201,9 @@ void FileLoaderRegistryImpl::removeAlgorithm(
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+template class Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>;
+}
+}
diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp
index 1e401863955..a65c41f0aa1 100644
--- a/Framework/API/src/FrameworkManager.cpp
+++ b/Framework/API/src/FrameworkManager.cpp
@@ -434,3 +434,9 @@ void FrameworkManagerImpl::setupUsageReporting() {
 
 } // namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::FrameworkManagerImpl>;
+}
+}
diff --git a/Framework/API/src/FuncMinimizerFactory.cpp b/Framework/API/src/FuncMinimizerFactory.cpp
index 0ce1a337938..1ca211a3916 100644
--- a/Framework/API/src/FuncMinimizerFactory.cpp
+++ b/Framework/API/src/FuncMinimizerFactory.cpp
@@ -60,3 +60,9 @@ FuncMinimizerFactoryImpl::createMinimizer(const std::string &str) const {
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::FuncMinimizerFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/FunctionFactory.cpp b/Framework/API/src/FunctionFactory.cpp
index ecaf3a3177c..9595e2eaeb4 100644
--- a/Framework/API/src/FunctionFactory.cpp
+++ b/Framework/API/src/FunctionFactory.cpp
@@ -317,3 +317,9 @@ void FunctionFactoryImpl::unsubscribe(const std::string &className) {
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::FunctionFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/ImplicitFunctionFactory.cpp b/Framework/API/src/ImplicitFunctionFactory.cpp
index 7d4c0360f09..8853faa93e6 100644
--- a/Framework/API/src/ImplicitFunctionFactory.cpp
+++ b/Framework/API/src/ImplicitFunctionFactory.cpp
@@ -49,5 +49,12 @@ ImplicitFunctionFactoryImpl::createUnwrapped(
       funcParser->createFunctionBuilder(pInstructionsXML));
   return functionBuilder->create();
 }
+
+}
+}
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionFactoryImpl>;
 }
 }
diff --git a/Framework/API/src/ImplicitFunctionParameterParserFactory.cpp b/Framework/API/src/ImplicitFunctionParameterParserFactory.cpp
index 90261e36d85..7a33f739470 100644
--- a/Framework/API/src/ImplicitFunctionParameterParserFactory.cpp
+++ b/Framework/API/src/ImplicitFunctionParameterParserFactory.cpp
@@ -41,5 +41,12 @@ ImplicitFunctionParameterParser *ImplicitFunctionParameterParserFactoryImpl::
   }
   return paramParser;
 }
+
+}
+}
+
+namespace Mantid{
+namespace Kernel{
+template class Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionParameterParserFactoryImpl>;
 }
 }
diff --git a/Framework/API/src/ImplicitFunctionParserFactory.cpp b/Framework/API/src/ImplicitFunctionParserFactory.cpp
index 9a13f894941..c91d812d9d1 100644
--- a/Framework/API/src/ImplicitFunctionParserFactory.cpp
+++ b/Framework/API/src/ImplicitFunctionParserFactory.cpp
@@ -71,5 +71,12 @@ ImplicitFunctionParserFactoryImpl::createImplicitFunctionParserFromXML(
 
   return createImplicitFunctionParserFromXML(pRootElem);
 }
+
+}
+}
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionParserFactoryImpl>;
 }
 }
diff --git a/Framework/API/src/InstrumentDataService.cpp b/Framework/API/src/InstrumentDataService.cpp
index 0c785af2aae..0d6910e65d8 100644
--- a/Framework/API/src/InstrumentDataService.cpp
+++ b/Framework/API/src/InstrumentDataService.cpp
@@ -11,3 +11,10 @@ InstrumentDataServiceImpl::InstrumentDataServiceImpl()
 
 } // Namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::InstrumentDataServiceImpl>;
+}
+}
+
diff --git a/Framework/API/src/RemoteJobManagerFactory.cpp b/Framework/API/src/RemoteJobManagerFactory.cpp
index adb8fa032ee..8032e26f4ea 100644
--- a/Framework/API/src/RemoteJobManagerFactory.cpp
+++ b/Framework/API/src/RemoteJobManagerFactory.cpp
@@ -82,3 +82,9 @@ RemoteJobManagerFactoryImpl::create(const std::string baseURL,
 
 } // namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::RemoteJobManagerFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/ScriptRepositoryFactory.cpp b/Framework/API/src/ScriptRepositoryFactory.cpp
index 7457917e337..9cc4fcf2d7e 100644
--- a/Framework/API/src/ScriptRepositoryFactory.cpp
+++ b/Framework/API/src/ScriptRepositoryFactory.cpp
@@ -17,3 +17,9 @@ ScriptRepositoryFactoryImpl::ScriptRepositoryFactoryImpl()
 
 } // namespace API
 } // namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+template class Mantid::Kernel::SingletonHolder<Mantid::API::ScriptRepositoryFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/TransformScaleFactory.cpp b/Framework/API/src/TransformScaleFactory.cpp
index 6de6bb9fe86..ebf72d081b4 100644
--- a/Framework/API/src/TransformScaleFactory.cpp
+++ b/Framework/API/src/TransformScaleFactory.cpp
@@ -43,5 +43,12 @@ TransformScaleFactoryImpl::createUnwrapped(const std::string &className) const {
   throw Kernel::Exception::NotImplementedError(
       "Don't use this method - use the safe one!!!");
 }
+
 } // namespace Mantid
 } // namespace API
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::TransformScaleFactoryImpl>;
+}
+}
diff --git a/Framework/API/src/WorkspaceFactory.cpp b/Framework/API/src/WorkspaceFactory.cpp
index c8cf2e6bbb8..bb40859b1c9 100644
--- a/Framework/API/src/WorkspaceFactory.cpp
+++ b/Framework/API/src/WorkspaceFactory.cpp
@@ -204,3 +204,9 @@ WorkspaceFactoryImpl::createPeaks(const std::string &className) const {
 
 } // namespace API
 } // Namespace Mantid
+
+namespace Mantid {
+namespace Kernel {
+  template class Mantid::Kernel::SingletonHolder<Mantid::API::WorkspaceFactoryImpl>;
+}
+}
diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h
index 616f5cb3936..7b1c490edc8 100644
--- a/Framework/Kernel/inc/MantidKernel/ConfigService.h
+++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h
@@ -352,13 +352,7 @@ private:
   std::vector<std::string> m_filterChannels;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#if defined(__APPLE__) && defined(__INTEL_COMPILER)
-inline
-#endif
-    template class MANTID_KERNEL_DLL
-        Mantid::Kernel::SingletonHolder<ConfigServiceImpl>;
+EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL  Mantid::Kernel::SingletonHolder<ConfigServiceImpl>;
 typedef Mantid::Kernel::SingletonHolder<ConfigServiceImpl>
     ConfigService;
 
diff --git a/Framework/Kernel/inc/MantidKernel/DllConfig.h b/Framework/Kernel/inc/MantidKernel/DllConfig.h
index f7a6020c17f..835e693444d 100644
--- a/Framework/Kernel/inc/MantidKernel/DllConfig.h
+++ b/Framework/Kernel/inc/MantidKernel/DllConfig.h
@@ -32,8 +32,10 @@
 
 #ifdef IN_MANTID_KERNEL
 #define MANTID_KERNEL_DLL DLLExport
+#define EXTERN_MANTID_KERNEL extern
 #else
 #define MANTID_KERNEL_DLL DLLImport
+#define EXTERN_MANTID_KERNEL extern
 #endif /* IN_MANTID_KERNEL*/
 
 #endif // MANTID_KERNEL_DLLCONFIG_H_
diff --git a/Framework/Kernel/inc/MantidKernel/LibraryManager.h b/Framework/Kernel/inc/MantidKernel/LibraryManager.h
index 089038d0c08..aa40347f6dd 100644
--- a/Framework/Kernel/inc/MantidKernel/LibraryManager.h
+++ b/Framework/Kernel/inc/MantidKernel/LibraryManager.h
@@ -69,13 +69,8 @@ private:
       OpenLibs;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// LibraryManagerImpl (needed for dllexport/dllimport) and a typedef for it.
-#if defined(__APPLE__) && defined(__INTEL_COMPILER)
-inline
-#endif
-    template class MANTID_KERNEL_DLL
-        Mantid::Kernel::SingletonHolder<LibraryManagerImpl>;
+
+EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<LibraryManagerImpl>;
 typedef Mantid::Kernel::SingletonHolder<LibraryManagerImpl>
     LibraryManager;
 
diff --git a/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h b/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h
index 46d3d0b9513..9168f8c91ba 100644
--- a/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h
+++ b/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h
@@ -46,14 +46,8 @@ private:
   ~PropertyManagerDataServiceImpl() override = default;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// PropertyManagerDataServiceImpl (needed for dllexport/dllimport) and a
-/// typedef for it.
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_KERNEL_DLL
-    Mantid::Kernel::SingletonHolder<PropertyManagerDataServiceImpl>;
-#endif /* _WIN32 */
+
+EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<PropertyManagerDataServiceImpl>;
 typedef  Mantid::Kernel::SingletonHolder<
     PropertyManagerDataServiceImpl> PropertyManagerDataService;
 
diff --git a/Framework/Kernel/inc/MantidKernel/UsageService.h b/Framework/Kernel/inc/MantidKernel/UsageService.h
index b3b461118e2..1ae9ad684a2 100644
--- a/Framework/Kernel/inc/MantidKernel/UsageService.h
+++ b/Framework/Kernel/inc/MantidKernel/UsageService.h
@@ -137,12 +137,8 @@ private:
   Poco::ActiveMethod<int, std::string, UsageServiceImpl> m_featureActiveMethod;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
-#if defined(__APPLE__) && defined(__INTEL_COMPILER)
-inline
-#endif
-    template class MANTID_KERNEL_DLL
+
+EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL
         Mantid::Kernel::SingletonHolder<UsageServiceImpl>;
 typedef Mantid::Kernel::SingletonHolder<UsageServiceImpl>
     UsageService;
diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp
index c9ef7f008cb..777c814b367 100644
--- a/Framework/Kernel/src/ConfigService.cpp
+++ b/Framework/Kernel/src/ConfigService.cpp
@@ -2040,6 +2040,10 @@ int ConfigServiceImpl::FindLowestFilterLevel() const {
 
   return lowestPriority;
 }
+
+
+template class Mantid::Kernel::SingletonHolder<ConfigServiceImpl>;
+
 /// \cond TEMPLATE
 template DLLExport int ConfigServiceImpl::getValue(const std::string &,
                                                    double &);
diff --git a/Framework/Kernel/src/LibraryManager.cpp b/Framework/Kernel/src/LibraryManager.cpp
index 6a22cad19e2..3aa4e86101a 100644
--- a/Framework/Kernel/src/LibraryManager.cpp
+++ b/Framework/Kernel/src/LibraryManager.cpp
@@ -134,5 +134,7 @@ bool LibraryManagerImpl::loadLibrary(const std::string &filepath) {
   return false;
 }
 
+template class Mantid::Kernel::SingletonHolder<LibraryManagerImpl>;
+
 } // namespace Kernel
 } // namespace Mantid
diff --git a/Framework/Kernel/src/PropertyManagerDataService.cpp b/Framework/Kernel/src/PropertyManagerDataService.cpp
index bd4587f31bf..ce7ea9564dd 100644
--- a/Framework/Kernel/src/PropertyManagerDataService.cpp
+++ b/Framework/Kernel/src/PropertyManagerDataService.cpp
@@ -9,5 +9,7 @@ namespace Kernel {
 PropertyManagerDataServiceImpl::PropertyManagerDataServiceImpl()
     : DataService<PropertyManager>("PropertyManagerDataService") {}
 
+template class Mantid::Kernel::SingletonHolder<PropertyManagerDataServiceImpl>;
+
 } // Namespace Kernel
 } // Namespace Mantid
diff --git a/Framework/Kernel/src/UsageService.cpp b/Framework/Kernel/src/UsageService.cpp
index 8130e67bf06..8836ff23832 100644
--- a/Framework/Kernel/src/UsageService.cpp
+++ b/Framework/Kernel/src/UsageService.cpp
@@ -302,5 +302,6 @@ int UsageServiceImpl::sendReport(const std::string &message,
   return status;
 }
 
+template class Mantid::Kernel::SingletonHolder<UsageServiceImpl>;
 } // namespace API
 } // namespace Mantid
diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h
index db73b6e65b0..dc77e2d0b54 100644
--- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h
+++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h
@@ -32,8 +32,10 @@
 
 #ifdef IN_MANTID_MDALGORITHMS
 #define MANTID_MDALGORITHMS_DLL DLLExport
+#define EXTERN_MANTID_MDALGORITHMS extern
 #else
 #define MANTID_MDALGORITHMS_DLL DLLImport
+#define EXTERN_MANTID_MDALGORITHMS extern
 #endif /* IN_MANTID_MDALGORITHMS*/
 
 #endif // MANTID_MDALGORITHMS_DLLCONFIG_H_
diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h
index 04380c802fd..e9a6146cd90 100644
--- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h
+++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h
@@ -64,16 +64,16 @@ private:
   using BaseClass::createUnwrapped;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// ForegroundModelFactoryImpl (needed for dllexport/dllimport).
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_MDALGORITHMS_DLL
-    Kernel::SingletonHolder<ForegroundModelFactoryImpl>;
-#endif /* _WIN32 */
 /// Typedef singleton instance to ForegroundFactory
 typedef Kernel::SingletonHolder<ForegroundModelFactoryImpl> ForegroundModelFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_MDALGORITHMS template class MANTID_MDALGORITHMS_DLL
+      Kernel::SingletonHolder<Mantid::MDAlgorithms::ForegroundModelFactoryImpl>;
+}
+}
+
 #endif /* MANTID_MDALGORITHMS_FOREGROUNDMODELFACTORY_H_ */
diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h
index 2d1b8750ea4..0576d374928 100644
--- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h
+++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h
@@ -63,17 +63,17 @@ private:
   using BaseClass::createUnwrapped;
 };
 
-/// Forward declaration of a specialisation of SingletonHolder for
-/// MDResolutionConvolutionFactoryImpl (needed for dllexport/dllimport).
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class MANTID_MDALGORITHMS_DLL
-    Kernel::SingletonHolder<MDResolutionConvolutionFactoryImpl>;
-#endif /* _WIN32 */
 /// Typedef singleton instance to MDResolutionConvolutionFactory
 typedef Kernel::SingletonHolder<
     MDResolutionConvolutionFactoryImpl> MDResolutionConvolutionFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTID_MDALGORITHMS template class MANTID_MDALGORITHMS_DLL
+      Kernel::SingletonHolder<Mantid::MDAlgorithms::MDResolutionConvolutionFactoryImpl>;
+}
+}
+
 #endif /* MANTID_MDALGORITHMS_MDRESOLUTIONCONVOLUTIONFACTORY_H_ */
diff --git a/Framework/MDAlgorithms/src/Quantification/ForegroundModelFactory.cpp b/Framework/MDAlgorithms/src/Quantification/ForegroundModelFactory.cpp
index 5320932439d..1e218687421 100644
--- a/Framework/MDAlgorithms/src/Quantification/ForegroundModelFactory.cpp
+++ b/Framework/MDAlgorithms/src/Quantification/ForegroundModelFactory.cpp
@@ -25,5 +25,12 @@ ForegroundModelFactoryImpl::createModel(const std::string &name,
   fgModel->setFunctionUnderMinimization(fitFunction);
   return fgModel;
 }
+
+}
+}
+
+namespace Mantid {
+namespace Kernel {
+  template class Kernel::SingletonHolder<Mantid::MDAlgorithms::ForegroundModelFactoryImpl>;
 }
 }
diff --git a/Framework/MDAlgorithms/src/Quantification/MDResolutionConvolutionFactory.cpp b/Framework/MDAlgorithms/src/Quantification/MDResolutionConvolutionFactory.cpp
index b01bbad62b5..3f2bc671c14 100644
--- a/Framework/MDAlgorithms/src/Quantification/MDResolutionConvolutionFactory.cpp
+++ b/Framework/MDAlgorithms/src/Quantification/MDResolutionConvolutionFactory.cpp
@@ -26,5 +26,12 @@ MDResolutionConvolution *MDResolutionConvolutionFactoryImpl::createConvolution(
   convolution->initialize();
   return convolution;
 }
+
+}
+}
+
+namespace Mantid {
+namespace Kernel {
+  template class Kernel::SingletonHolder<Mantid::MDAlgorithms::MDResolutionConvolutionFactoryImpl>;
 }
 }
diff --git a/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h b/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h
index 794db1cc8cc..aefb628ce32 100644
--- a/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h
+++ b/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h
@@ -93,13 +93,13 @@ private:
   friend struct Mantid::Kernel::CreateUsingNew<AlgorithmInputHistoryImpl>;
 };
 
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-  template class EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl>;
-#endif /* _WIN32 */
-  /// The specific instantiation of the templated type
-  typedef Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl> AlgorithmInputHistory;
+typedef Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl> AlgorithmInputHistory;
+}
+}
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder<MantidQt::API::AlgorithmInputHistoryImpl>;
 }
 }
 
diff --git a/MantidQt/API/inc/MantidQtAPI/DllOption.h b/MantidQt/API/inc/MantidQtAPI/DllOption.h
index c6ffb39d8b6..d20c46208d4 100644
--- a/MantidQt/API/inc/MantidQtAPI/DllOption.h
+++ b/MantidQt/API/inc/MantidQtAPI/DllOption.h
@@ -5,8 +5,10 @@
 
 #ifdef IN_MANTIDQT_API
 #define EXPORT_OPT_MANTIDQT_API DLLExport 
+#define EXTERN_MANTIDQT_API extern
 #else
 #define EXPORT_OPT_MANTIDQT_API DLLImport
+#define EXTERN_MANTIDQT_API extern
 #endif /* IN_MANTIDQT_API */
 
 #endif //MANTIDQT_API_DLLOPTION_H_
diff --git a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
index 694792b5f45..a43040369e5 100644
--- a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
+++ b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h
@@ -69,11 +69,7 @@ private:
   ~AlgorithmDialogFactoryImpl() override = default;
 };
 
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class EXPORT_OPT_MANTIDQT_API
-    Mantid::Kernel::SingletonHolder<AlgorithmDialogFactoryImpl>;
-#endif /* _WIN32 */
+
 /// The specific instantiation of the templated type
 typedef Mantid::Kernel::SingletonHolder<
     AlgorithmDialogFactoryImpl> AlgorithmDialogFactory;
@@ -184,15 +180,19 @@ void UserSubWindowFactoryImpl::saveAliasNames(const std::string &realName) {
   }
 }
 
-#ifdef _WIN32
-// this breaks new namespace declaraion rules; need to find a better fix
-template class EXPORT_OPT_MANTIDQT_API
-    Mantid::Kernel::SingletonHolder<UserSubWindowFactoryImpl>;
-#endif /* _WIN32 */
 /// The specific instantiation of the templated type
 typedef Mantid::Kernel::SingletonHolder<
     UserSubWindowFactoryImpl> UserSubWindowFactory;
 }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API
+      Mantid::Kernel::SingletonHolder<MantidQt::API::AlgorithmDialogFactoryImpl>;
+  EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API
+      Mantid::Kernel::SingletonHolder<MantidQt::API::UserSubWindowFactoryImpl>;
+}
+}
+
 #endif // MANTIDQT_API_INTERFACEFACTORY_H_
diff --git a/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h b/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h
index 3566bf08d26..6a472246c49 100644
--- a/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h
+++ b/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h
@@ -64,15 +64,15 @@ namespace MantidQt
       friend struct Mantid::Kernel::CreateUsingNew<SelectionNotificationServiceImpl>;      
    };
 
-   /// Forward declaration of a specialisation of SingletonHolder for SelectionNotificationServiceImpl
-   /// (needed for dllexport/dllimport) and a typedef for it.
-#ifdef _WIN32
-  template class EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder<SelectionNotificationServiceImpl>;
-#endif /* _WIN32 */
-
   typedef Mantid::Kernel::SingletonHolder<SelectionNotificationServiceImpl> SelectionNotificationService;
 
   }
 }
 
+namespace Mantid {
+namespace Kernel {
+  EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder<MantidQt::API::SelectionNotificationServiceImpl>;
+}
+}
+
 #endif // MANTIDQTAPI_SELECTION_NOTIFICATION_SERVICE_H_
diff --git a/MantidQt/API/src/AlgorithmInputHistory.cpp b/MantidQt/API/src/AlgorithmInputHistory.cpp
index ae0cc53a0c1..0a8307c6fe1 100644
--- a/MantidQt/API/src/AlgorithmInputHistory.cpp
+++ b/MantidQt/API/src/AlgorithmInputHistory.cpp
@@ -149,3 +149,5 @@ void AbstractAlgorithmInputHistory::load()
   
   settings.endGroup();
 }
+
+template class Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl>;
diff --git a/MantidQt/API/src/InterfaceFactory.cpp b/MantidQt/API/src/InterfaceFactory.cpp
index d1f5a8d4343..d444a240d9e 100644
--- a/MantidQt/API/src/InterfaceFactory.cpp
+++ b/MantidQt/API/src/InterfaceFactory.cpp
@@ -109,4 +109,5 @@ UserSubWindow * UserSubWindowFactoryImpl::createFromAlias(const std::string & na
   }
 }	
 
-
+template class Mantid::Kernel::SingletonHolder<AlgorithmDialogFactoryImpl>;
+template class Mantid::Kernel::SingletonHolder<UserSubWindowFactoryImpl>;
diff --git a/MantidQt/API/src/SelectionNotificationService.cpp b/MantidQt/API/src/SelectionNotificationService.cpp
index 428f83720a2..8bcac063049 100644
--- a/MantidQt/API/src/SelectionNotificationService.cpp
+++ b/MantidQt/API/src/SelectionNotificationService.cpp
@@ -38,4 +38,4 @@ void SelectionNotificationServiceImpl::sendQPointSelection( bool lab_coords, dou
 //  std::cout << "QPointSelection_signal emitted" << std::endl;
 }
 
-
+template class Mantid::Kernel::SingletonHolder<SelectionNotificationServiceImpl>;
-- 
GitLab