In our MvxApplication
, I'm using the EndingWith
method to register our Repositories.
I used this approach in a different project where our App.cs and our Repositories were in the same project, and everything worked properly. Now that I've moved the App.cs into a separate project, the MvvmCross IOC doesn't register the dependencies from our core app.
The initialize method
public override void Initialize() {
// stuff happens here
// Register all repositories
CreatableTypes().EndingWith("Repository").AsInterfaces().RegisterAsLazySingleton();
// more stuff happens here
// Resolve the DbVersionRepo to run migrations.
// This line is breaking
var databaseVersionRepository = MvxSimpleIoCContainer.Instance.Resolve < IDatabaseVersionRepository > ();
}
The repository in question
public class DatabaseVersionRepository : RepositoryBase, IDatabaseVersionRepository
{
// do stuff
}
The Exception
Cirrious.CrossCore.Exceptions.MvxException: Failed to resolve type OurApp.AppCore.Repositories.IDatabaseVersionRepository
12-10 10:35:43.275 E/mono (24043):
12-10 10:35:43.275 E/mono (24043): Unhandled Exception:
12-10 10:35:43.275 E/mono (24043): Cirrious.CrossCore.Exceptions.MvxException: Failed to resolve type OurApp.AppCore.Repositories.IDatabaseVersionRepository
12-10 10:35:43.275 E/mono (24043): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00000] in <filename unknown>:0
12-10 10:35:43.275 E/mono (24043): at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve[IDatabaseVersionRepository] () [0x00000] in <filename unknown>:0
12-10 10:35:43.275 E/mono (24043): at OurApp.CustomApp.Core.App.Initialize () [0x00135] in c:\Projects\OurApp\OurApp.Droid\App.cs:63
12-10 10:35:43.275 E/mono (24043): at Cirrious.MvvmCross.Platform.MvxSetup.CreateAndInitializeApp (IMvxPluginManager pluginManager) [0x00000] in <filename unknown>:0
12-10 10:35:43.275 E/mono (24043): at Cirrious.MvvmCross.Platform.MvxSetup.InitializeApp (IMvxPluginManager pluginManager) [0x00000] in <filename unknown>:0
12-10 10:35:43.275 E/mono (24043): at Cirrious.MvvmCross.Platform.MvxSetup.InitializeSecondary () [0x00000] in <filename unknown>:0
12-10 10:35:43.275 E/mono (24043): at Cirrious.MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__5 (System.Object ignored) [0x00000] in <filename unknown>:0
The program 'Mono' has exited with code 0 (0x0).
The project structure is something like this.
OurCompany.AppCore
\ Repositories
\IDatabaseVersionRepository.cs
\DatabaseVersionRepository.cs
OurCompany.CustomApp.Core
\ App.cs
OurCompany.CustomApp.Droid.Ui
\ Setup.cs
I should also note that I tried this approach but got the same results.
CreatableTypes().Inherits<IDatabaseVersionRepository>().AsInterfaces().RegisterAsLazySingleton();
As per Stuart's comment above, the way to resolve dependencies that live outside the current assembly is to do the following.
typeof(RepositoryBase).Assembly
.CreatableTypes()
.EndingWith("Repository")
.AsInterfaces()
.RegisterAsLazySingleton();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.