private static IUnitOfWorkFactory LoadFactory(Datastore datastore) { var type = Type.GetType(datastore.UnitOfWorkFactory, LoadAssembly, (assembly, name, insensitive) => assembly.GetType(name, true, insensitive)); var factory = LoadFactory(type, datastore); return factory; }
private static IUnitOfWorkFactory LoadFactory(Type type, Datastore datastore) { var mappings = LoadMappings(datastore.Mappings); var ctor = type.GetConstructors().FirstOrDefault(); if (ctor == null) { throw new TypeLoadException("Could not find a constructor for the specified UnitOfWorkFactory."); } var parameters = mappings == null ? new object[] { datastore.Connection } : new object[] { datastore.Connection, mappings }; var instance = ctor.Invoke(parameters) as IUnitOfWorkFactory; if (instance == null) { throw new InvalidCastException(datastore.UnitOfWorkFactory + " is not a valid IUnitOfWorkFactory."); } return instance; }