merken / Prise

A .NET Plugin Framework.
https://merken.github.io/Prise
MIT License
362 stars 40 forks source link

How to use it in desktop application? #1

Closed waliarubal closed 5 years ago

waliarubal commented 5 years ago

I have a .NET core 2.2 based Avalonia desktop application in which I want to use your framework. Let me know how shall I use your framework. Below is my current code for loading.

IServiceScope RegisterServices()
        {
            var collection = new ServiceCollection();

            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (var assembly in assemblies)
            {
                if (!assembly.FullName.StartsWith("Jaya", StringComparison.InvariantCultureIgnoreCase))
                    continue;

                var types = assembly.DefinedTypes;
                foreach (TypeInfo typeInfo in types)
                    if (typeInfo.IsClass && typeInfo.Name.EndsWith("Service", StringComparison.InvariantCulture))
                        collection.AddScoped(typeInfo);
            }

            var container = collection.BuildServiceProvider();
            var scopeFactory = container.GetRequiredService<IServiceScopeFactory>();
            return scopeFactory.CreateScope();
        }
merken commented 5 years ago

Hi, thanks for your interest in Prise. I have a Azure functions example in the pipeline for this, and will be looking into creating an Avalon plugin as well. Can you be more specific about what exactly your plugin does ?

waliarubal commented 5 years ago

Mine is a very complex desktop application. It relies on several services (providers or plugins; whatever you want to call) which I would like to hold in different assemblies and load them dynamically. You can see my app here.

When you will visit my app's page, you will see explorer based interface. Each root node in explorer's left tree will be a separate service which I want to load from an assembly.

merken commented 5 years ago

I see. I've been looking into it, you can follow the progress here : https://github.com/merken/Jaya/commits?author=merken

waliarubal commented 5 years ago

Thanks, nice work, much appreciated.

I have implemented the plugin system using MEF now. Its working fabulously. You can checkout my latest code.

waliarubal commented 5 years ago

Closing issue for now since it no more appears to be a valid scenario for me. Thanks mate!

merken commented 5 years ago

For reference, please see complete working example at https://github.com/merken/Prise/tree/master/examples/AvaloniaAppWithPlugin