Skip to content

Use SplatRegistrations.Register with Generic #137

Open
@mysteryx93

Description

@mysteryx93

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions