Splat.DI.SourceGenerator icon indicating copy to clipboard operation
Splat.DI.SourceGenerator copied to clipboard

Use SplatRegistrations.Register with Generic

Open mysteryx93 opened this issue 3 years ago • 3 comments

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 avatar Jul 30 '22 21:07 mysteryx93

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

SplatRegistrations.Register<IAppUpdateService, AppUpdateService<TSettings>>();

mysteryx93 avatar Aug 31 '22 16:08 mysteryx93

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.

glennawatson avatar Aug 31 '22 18:08 glennawatson

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
Hi, I'm writing Avalonia desktop app and I have VM that looks like: public class SampleViewModel<T> : ReactiveObject, IRoutableViewModel, ISampleViewModel {...} interface ISampleViewModel...

AlienJust avatar Dec 07 '22 06:12 AlienJust