Maybe? In principal I'm all for making stuff more injectable even more so 
if theres a pull-request :D

Two things: 
1) there should probably be an IMigrationFactory interface which defaults 
to an Activator.CreateInstance implementation just to make supporting di 
containers easier
2) The constructor should probably allow for injecting the 
MigrationVersionStoreFactory.

On Wednesday, November 12, 2014 10:21:49 AM UTC-5, Jan Schubert wrote:
>
> Good work! I try to integrate the Migration Framework in my application 
> and it looks good!
>
> But now I need some informations in my migration class and I want to add 
> constructor parameters. Currently, your NHibernate.Migrations.Migrator 
> initializes the migration classes without parameters. 
> (Activator.CreateInstance(t))
>
> I want to use a dependency injection framework. Can you change the 
> migrator like this or should I write my own migrator?
>
> public Migrator(ISessionFactory sessionFactory, Func<System.Type, object> 
> createInstance = null)
> {
>  if (createInstance == null)
>  createInstance = Activator.CreateInstance;
>
>
>  _sessionFactory = (ISessionFactoryImplementor)sessionFactory;
>
>
>  var migrationVersionStoreFactory = _sessionFactory.Settings.
> MigrationVersionStoreFactory;
>
>
>  if (migrationVersionStoreFactory == null)
>  {
>  throw new HibernateConfigException(
>  "Tried to initialize a migrator without setting 
> migration.versionstorefactory");
>  }
>
>
>  _migrationVersionStore = migrationVersionStoreFactory.
> GetMigrationVersionStore(_sessionFactory, _sessionFactory.Settings.
> MigrationContext);
>  
>  
>  _registeredMigrations = _sessionFactory.Settings.RegisterdMigrations
>    .Select(t => createInstance(t))
>    .Cast<IMigration>()
>    .OrderBy(x=>x.GetVersion(), new MigrationVersionComparitor())
>    .ToList();
>
>
> }
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to