Forum Xamarin Cross Platform with Xamarin

TinyIOC and XPlat IOC containers

LeelaPrasannaKumarLeelaPrasannaKumar USUniversity
edited October 2013 in Cross Platform with Xamarin

Dear all,

I was trying to consume these as alternatives to Ninject ..cross platform IOC containers

I wanted to have something like this

interface IServiceProvider

class OnlineProvider : IServiceProvider   //for network cases

class OfflineProvider : IServiceProvider   //for no network cases

Now I have a class that contains:

            class Consumer
               [Inject, OnlineAttribute] // attribute
               IServiceProvider OnlineProviderHandle;

               [Inject, OfflineAttribute]
               IServiceProvider OfflineProviderHandle;

I my bindings for IOC. I was able to achieve using Ninject the following..



Is there any way to achieve this in TinyIOC or XPlat
I haven't seen a way that can be done using attributes. And in such scenarios where multiple instances of same Interface type are possible, how do we resolve or register.????


  • JonathanPeppersJonathanPeppers USInsider, Beta, University ✭✭

    I would just register the two separate classes.

    If you need the offline version versus online, just pull in the appropriate one you need. You can also store and access the class from an IServiceProvider variable in case you need to change it later.

  • LeelaPrasannaKumarLeelaPrasannaKumar USUniversity
    edited October 2013

    Hi Jonathan

    What I understood from your proposal, have a IServiceProvider variable

    IServiceProvider _serviceprovider;
    if ( netwrok available)
    _serviceprovider = //Resolve for Online concrete implementation
    _serviceprovider = //Resolve the offline concrete implementation

    This way I would not achieve IOC as I am referring concrete implementation inside my code
    Please suggest

  • Create two separate interfaces:

    interface IServiceProviderOnline : IServiceProvider {}

    interface IServiveProviderOffline : IserviceProvider {}

  • LeelaPrasannaKumarLeelaPrasannaKumar USUniversity

    Thanks Oystein. That should work

  • LeelaPrasannaKumarLeelaPrasannaKumar USUniversity
    edited October 2013

    One more question to.. enable property injection should I have to create the object ?
    I have seen it in the examples. OR is there anyway to say auto resolve all property injections?

    var input = new TestClassPropertyDependencies();
    container.BuildUp(input); // Properties are now set
Sign In or Register to comment.