diff --git a/GBase/Exceptions/InvalidTableTypeException.cs b/GBase/Exceptions/InvalidTableTypeException.cs
new file mode 100644
index 0000000..9be6013
--- /dev/null
+++ b/GBase/Exceptions/InvalidTableTypeException.cs
@@ -0,0 +1,27 @@
+// Author: Simon Gockner
+// Created: 2020-09-18
+// Copyright(c) 2020 SimonG. All Rights Reserved.
+
+using System;
+using GBase.Api;
+
+namespace GBase.Exceptions
+{
+ ///
+ /// that the passed table type doesn't implement "/>
+ ///
+ public class InvalidTableTypeException : Exception
+ {
+ ///
+ /// that the passed table type doesn't implement "/>
+ ///
+ /// The table type
+ public InvalidTableTypeException(Type type)
+ : base($"Table type ({type}) doesn't implement {nameof(INotifyGBaseEntryChanged)}.")
+ {
+ Type = type;
+ }
+
+ public Type Type { get; }
+ }
+}
\ No newline at end of file
diff --git a/GBase/Factories/GBaseTableFactory.cs b/GBase/Factories/GBaseTableFactory.cs
new file mode 100644
index 0000000..70d3062
--- /dev/null
+++ b/GBase/Factories/GBaseTableFactory.cs
@@ -0,0 +1,46 @@
+// Author: Simon Gockner
+// Created: 2020-09-18
+// Copyright(c) 2020 SimonG. All Rights Reserved.
+
+using System;
+using GBase.Api;
+using GBase.Exceptions;
+using GBase.FileHandling.Factories;
+using GBase.Interfaces;
+using GBase.Interfaces.FileHandling;
+
+namespace GBase.Factories
+{
+ ///
+ /// Factory for the
+ ///
+ public class GBaseTableFactory : IGBaseTableFactory
+ {
+ private readonly IFileHandlerFactory _fileHandlerFactory;
+ private readonly IGBaseColumnFactory _gBaseColumnFactory;
+
+ ///
+ /// Factory for the
+ ///
+ /// Factory for the
+ /// Factory for the
+ public GBaseTableFactory(IFileHandlerFactory fileHandlerFactory, IGBaseColumnFactory gBaseColumnFactory)
+ {
+ _fileHandlerFactory = fileHandlerFactory;
+ _gBaseColumnFactory = gBaseColumnFactory;
+ }
+
+ ///
+ /// Creates an
+ ///
+ /// A newly created instance of the implementation for
+ public IGBaseTable Create(Type type)
+ {
+ if (!typeof(INotifyGBaseEntryChanged).IsAssignableFrom(type))
+ throw new InvalidTableTypeException(type);
+
+ Type gBaseTableType = typeof(GBaseTable<>).MakeGenericType(type);
+ return (IGBaseTable) Activator.CreateInstance(gBaseTableType, _fileHandlerFactory, _gBaseColumnFactory);
+ }
+ }
+}
\ No newline at end of file
diff --git a/GBase/Factories/IGBaseTableFactory.cs b/GBase/Factories/IGBaseTableFactory.cs
index 43792c0..11c8554 100644
--- a/GBase/Factories/IGBaseTableFactory.cs
+++ b/GBase/Factories/IGBaseTableFactory.cs
@@ -3,6 +3,7 @@
// Copyright(c) 2020 SimonG. All Rights Reserved.
+using System;
using GBase.Interfaces;
namespace GBase.Factories
@@ -16,6 +17,6 @@ namespace GBase.Factories
/// Creates an
///
/// A newly created instance of the implementation for
- IGBaseTable Create();
+ IGBaseTable Create(Type type);
}
}
\ No newline at end of file
diff --git a/GBase/GBase.cs b/GBase/GBase.cs
index 6008166..4a789a3 100644
--- a/GBase/GBase.cs
+++ b/GBase/GBase.cs
@@ -75,7 +75,7 @@ namespace GBase
if (gBaseTableAttribute == null)
continue;
- IGBaseTable gBaseTable = _gBaseTableFactory.Create();
+ IGBaseTable gBaseTable = _gBaseTableFactory.Create(type);
await gBaseTable.Init(type, type.Name, Settings.DatabasePath, cancellationToken);
AddTable(gBaseTable);
diff --git a/GBase/Installers/GBaseInstaller.cs b/GBase/Installers/GBaseInstaller.cs
index 9ace16d..902e7cd 100644
--- a/GBase/Installers/GBaseInstaller.cs
+++ b/GBase/Installers/GBaseInstaller.cs
@@ -19,12 +19,11 @@ namespace GBase.Installers
public void Install(IIocContainer container)
{
container.Register();
- container.Register();
container.Register();
//factories
container.RegisterFactory();
- container.RegisterFactory();
+ container.Register(); //TODO: Once LightweightIocContainer can handle open generic registrations this can be changed back again
container.RegisterFactory();
}
}