Forum Xamarin.Forms

Xamarin xaml forms with FreshMvvm and using multiple IOC registration

Rahul6.yRahul6.y USMember

Hi I am working with FreshMvvm and I can put multiple table in one data service and registered on single IOC but I need to do it in way that I can have separation IOC's for tables?
Is there any example method available?

Kind Regards,
Rahul

Posts

  • Rahul6.yRahul6.y USMember

    Hi @MichaelRidland,

    Can you please let me know any example of freshMVvm with Sqlite.net.pcl.

    I try to create table using the method of FreshIOC.Container.Register<IDatabaseService, DatabaseService>();

    public class DatabaseService : IDatabaseService
    {
    static object locker = new object();

        SQLiteConnection _database;
        public DatabaseService()
        {
            _database = DependencyService.Get<IDatabase>().DBConnect();
            _database.CreateTable<TableA>();
            _database.CreateTable<TableB>();
            _database.CreateTable<TableC>();
            _database.CreateTable<TableD>();
            _database.CreateTable<TableE>();
            _database.CreateTable<TableF>();
        }
    
        I can see that all the table has been created but the Sql Exception has thrown and it has been attached 
    
  • MichaelRidlandMichaelRidland AUInsider, University ✭✭✭

    Hi,

    This is not really to do with FreshMvvm.

    It's a issue with your application, not sure you've given enough details for anyone to help you solve it.

    Thanks

  • Rahul6.yRahul6.y USMember

    Hi @MichaelRidland , thank you for coming back and yes you are correct and I made a mistake on my application and now it is working as expected and I just wanted to know whether the FreshMvvm supports Multiple ICS's?
    Because I have models and generic type of Repository and I have created the repository for each table and bind them with ModelView/PageModel and views/Pages. so I have to put the generic type to put IOC.Register as shown below:-

    public class App : Application
    {
    public App()
    {
    SetupIOC();
    // The root page of your application
    MainPage = new NavigationPage(new LaunchPage(this));
    }

    void SetupIOC()
    {
        FreshIOC.Container.Register<IObjectARepository, ObjectARepository>();
        FreshIOC.Container.Register<IObjectBRepository, ObjectARepository>();
    }
    

    I have attached some of my code sniper and please let me know whether it is possible to do!

    Kind Regards
    Rahul

  • MichaelRidlandMichaelRidland AUInsider, University ✭✭✭

    This code is incorrect, why would you register ObjectARepository for the interface IObjectBRepository? It's likely you'll need a ObjectBRepository.

  • Rahul6.yRahul6.y USMember

    Thank Michael and yes, that is correct that was my typo mistake.
    But now everything is working great with one IOC's and my next step is to split it out as my previous design for decouple the codes. If I am stack I will shout on here :smile:

  • Rahul6.yRahul6.y USMember

    Hi Michael,
    I am using FreshMvvm and FreshEssential to binding the data's but I couldn't marry both together is there any example help available with both mix. Because when I use FreshEssential example with FreshMvvm it is throwing a error as "FreshTinyIoC.TinyIoCResolutionException: Unable to resolve type: IoT.CustomerPage"
    Can you please let me know any single example with both using

    Would you please help me with Modelview with FreshMvvm and FreshEssential.

    Kind Regards,
    Rahul

  • MichaelRidlandMichaelRidland AUInsider, University ✭✭✭

    Hi @Rahul6.y

    Please look at your output window for more information on what the issues is.

    Thanks

  • Rahul6.yRahul6.y USMember

    Hi @MichaelRidland , thank you for the replay and I have been trying for two days but could not be able to find rest of the trace as it is because of Xaml trace doesn't give much information. However, if you could tell me how to marry FreshMvvm and FreshEssential together it would be great help.

    Kind Regards,
    Rahul

  • MichaelRidlandMichaelRidland AUInsider, University ✭✭✭

    So what the output from the Window?

  • Rahul6.yRahul6.y USMember

    Hi @MichaelRidland ,

    Sorry for the late response due to dredged to a new project. Yes, it was my mistake that I did not include the reference in the Android project and after that is working and I have saved lots of code now :) great tool.

Sign In or Register to comment.