Strypper / mauisland

MAUIsland 🏝️ is the number 1 controls gallery for .NET MAUI
MIT License
198 stars 14 forks source link

[Bug]: ViewModel migrations #191

Closed Strypper closed 5 months ago

Strypper commented 8 months ago

image

Contact Details

futurewingsstrypper@outlook.com

What happened?

We are currently in the process of refactoring MAUIsland, but we have encountered a challenge regarding ViewModels. Our intention is to centralize these ViewModels within the core framework, allowing them to be reused across different MAUI projects in the future.

However, this has resulted in the ViewModels being in different namespaces. Renaming from MAUIsland to MAUIsland.Core has caused issues with the extension method RegisterPages not being able to register properly. As our expertise lies more in assembly, we have yet to find a solution to address this.

    static MauiAppBuilder RegisterPages(this MauiAppBuilder builder, string pattern = "Page")
    {
        var assemblies = new Assembly[] { typeof(MauiProgram).Assembly };
        var pageTypes = assemblies.SelectMany(a => a.GetTypes().Where(a => a.Name.EndsWith(pattern) && !a.IsAbstract && !a.IsInterface));
        foreach (var pageType in pageTypes)
        {
            var viewModelFullName = $"{pageType.FullName}ViewModel";
            var viewModelType = Type.GetType(viewModelFullName);

            builder.Services.AddTransient(pageType);

            if (viewModelType != null)
                builder.Services.AddTransient(viewModelType);

            if (pageType.IsAssignableTo(typeof(IGalleryPage)))
            {
                Routing.RegisterRoute(pageType.FullName, pageType);
            }
        }

        return builder;
    }

Could you please assist us with this matter whenever you have some free time?

Version

7.0

What platforms are you seeing the problem on?

Windows

Relevant log output

None

Code of Conduct

Strypper commented 5 months ago

Resolved