i'm trying to use an OCR in Xamarin Mvvmcross 4.4.0 (not Xamarin.Forms) i want to avoid coding in platform specific. i've found tesseract but this library need coding in platform specific, i tried to inject with..
1.- SetUp.cs
protected override IMvxIocOptions CreateIocOptions()
{
return new MvxIocOptions()
{
PropertyInjectorOptions = MvxPropertyInjectorOptions.MvxInject
};
}
2.- view model
[MvxInject]
ITesseractApi _tesseract
{
get {
return Mvx.Resolve<ITesseractApi>();
//return Mvx.IocConstruct<ITesseractApi>();
}
}
but both ( resolve, IocConstruct ) fail, if there's any idea or alternative ...
First of all you have to inject the dependencies to IOC container in order for it to be able to resolve them. You can do it like that in MvvmCross:
Mvx.RegisterSingleton<IFoo>(new Foo());
This registers dependency as singleton. You might or might not want to choose different lifetime. Foo
is implementation of IFoo
in this case.
You mentioned that you want to code your login in PCL. You can absolutely do just that by registering ITesseractApi
dependency in platform specific projects (different instances of ITesseractApi
on iOS and Android projects) and resolving it in your PCL. As far as I can tell from their docs, there is no way to create an instance of TesseractApi
in shared code (notice Android constructor takes Context
as an argument)
So your PCL will use different (platform specific) code on different platforms trough an abstraction of ITesseractApi
.