question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddMigration extension method for non-generic ITypeConfiguration

See original GitHub issue

Hey,

I try to manage my own MigrationSystem for registering migrations by XML model versions for my types. Therefore I’ve a Dictionary with type as key and a List of Migrations (classes based on IEnumerable<Action<XElement>>) as value.

My problem is applying this migrations directly on ConfigurationContainer is not possible because I don’t have generic ITypeConfiguration objects. My algorithmn is:

  • Manage my Migration in MigrationSystem (outside in a static configuration manner).
  • Iterate over ConfigurationContainer and try to call AddMigration for ITypeConfiguration - if a migration is configured for the type.

But ExtensionMethod AddMigration can only be called for ITypeConfiguration<> and not ConfigurationContainer Enumerator values of type ITypeConfiguration. I’ve also tried to directly use With<MigrationsExtension>.Apply() but this is internal.

Currently workaround is applying migrations directly during creation of ContainerContainer. Therefore I can call Type<> and then AddMigration<>. But this must be done for every type which feels wrong.

Does anyone have a better suggestion? Is it ok to provide a AddMigration extension method for ITypeConfiguration.

Regards Thomas

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thomasjoschtcommented, Dec 3, 2020

Hey @Mike-E-angelo, thx a lot. My tests were successful. It think it should work with this new AddMigration methods. I’ll let you know in case I need anything else in next few days. But for now my demand is covered 😊

1reaction
thomasjoschtcommented, Dec 3, 2020

As further suggestion: It should be possible to write an AddMigration method for non-generic version of ITypeConfiguration like this. Therefore MigrationExtension must not be exposed. What do you think? Perhaps we could try this too.

public static ITypeConfiguration AddMigration(this ITypeConfiguration @this, IEnumerable<Action<XElement>> migrations)
   => @this.Root.With<MigrationsExtension>()
      .Apply(@this.Get(), migrations.Fixed())
      .Return(@this);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Extension methods must be defined in a non-generic static ...
The class which defines an extension method must be non-generic , static and non-nested; Every extension method must be a static method; The ......
Read more >
Extension method must be defined in a non-generic static class
In this video, I am going to fix this issue in C# i.e CS1106 : Extension method must be defined in a non...
Read more >
Compiler Error CS1106
Extension methods must be defined in a non generic static class. ... CS1106 because the class Extensions is not defined as static :....
Read more >
Extension method must be defined in a non-generic class
So I was following a CatLikeCoding tutorial, and when I finished with the second part of the tutorial, I go to Unity and...
Read more >
Extension methods
Static types and dynamic; API conflicts ... Implementing generic extensions; Resources. Extension methods add functionality to existing libraries.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found