Skip to content

A self-contained Xamarin.Forms style DependencyService implementation for all .NET 6.0 and later platforms.

License

Notifications You must be signed in to change notification settings

inthehand/InTheHand.DependencyInjection

Repository files navigation

InTheHand.DependencyInjection

A self-contained implementation of the Xamarin.Forms DependencyService for all .NET 6.0 (and later) platforms. Usage is the same as in Xamarin forms with the exception that DependencyAttribute is not currently used to register types automatically.

Xamarin.Forms DependencyService Introduction - Microsoft Learn

Usage

Register a type with DependencyService.Register<YourType>(); or with an interface and a specific implementation using DependencyService.Register<IYourInterface, YourType>();

Retrieve an instance with DependencyService.Get<IYourInterface>(); using the interface or class type your registered. Optionally specify whether to return a global instance or a new instance using the fetchTarget argument. e.g. for a new instance: var newInstance = DependencyService.Get<IYourInterface>(DependencyFetchTarget.NewInstance);

This class extends the DependencyService with support for parameterized constructors. For example when registering a type MyType with a default constructor of the form MyType(IService1 service1, IService2 service2) the DependencyService will look up those types in the container and instantiate these using either a singleton or a new instance depending on how they were registered and inject them into the constructor. The types referenced must have been registered with DependencyService prior to the call to Get which references them.

Nuget

About

A self-contained Xamarin.Forms style DependencyService implementation for all .NET 6.0 and later platforms.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages