reactiveui / Splat.DI.SourceGenerator

MIT License
30 stars 5 forks source link

Use SplatRegistrations.Register with Generic #137

Open mysteryx93 opened 2 years ago

mysteryx93 commented 2 years ago

Is it possible to use SplatRegistrations like this?

It says:

ViewModelLocator.cs(64, 9): [SPLATDI001] TConcrete has more than one constructor and one hasn't been marked with DependencyInjectionConstructorAttribute
public static void RegisterWithDesign<TInterface, TDesign>(this IMutableDependencyResolver resolver)
    where TDesign : TInterface, new() => RegisterWithDesign<TInterface, TInterface, TDesign>(resolver);

public static void RegisterWithDesign<TInterface, TConcrete, TDesign>(this IMutableDependencyResolver resolver)
    where TDesign : TInterface, new()
{
    SplatRegistrations.Register<TInterface, TConcrete>("Init");
    resolver.Register<TInterface>(() =>
        Design.IsDesignMode ? new TDesign() : Locator.Current.GetService<TInterface>("Init"));
}

If not; it could be a neat feature to add.

mysteryx93 commented 2 years ago

Even this is not currently working. That's a big problem.

SplatRegistrations.Register<IAppUpdateService, AppUpdateService<TSettings>>();
glennawatson commented 2 years ago

Be likely a change needed in the Roslyn scanning.

I'm not going to get to making this change for a little while if you get on slack at some point I could help you with the code to provide a PR.

AlienJust commented 1 year ago

Even this is not currently working. That's a big problem.

Hi, how do You think, is this behavior could be related: https://github.com/reactiveui/ReactiveUI/discussions/3440 ?

GitHub
Generic routable viewmodel · Discussion #3440 · reactiveui/ReactiveUI
Hi, I'm writing Avalonia desktop app and I have VM that looks like: public class SampleViewModel<T> : ReactiveObject, IRoutableViewModel, ISampleViewModel {...} interface ISampleViewModel...