I have a Wallet class that I get from a repository. I'm trying to properly register both in Autofac so classes using the wallet could have a proper instance injected. The problem is that the repository uses an async method (returning Task). Does Autofac support such cases?
This doesn't work:
cb.RegisterType<WalletRepository>()
.As<IWalletRepository>()
.SingleInstance();
cb.Register(async c => await c.Resolve<IWalletRepository>().CreateAsync(App.WalletPath));
cb.RegisterType<ViewModel>()
.AsSelf().
.SingleInstance();
Somewhere in the app I just have:
class ViewModel
{
public ViewModel(Wallet wallet)
{
//nothing fancy here
}
}
When calling container.Resolve<ViewModel>() i get an exception saying Wallet is not registered.