I am using Autofac in Xamarin Android app, the container returns null object reference because nothing is assigned to the container until a block of code is ran. However, i'm not sure how to make the block of code actually run. This is probably a simple issue but just on case, here is use of the container:
public void AddToCartnBtn_Click(object sender, EventArgs e)
{
using (var scope = App.Container.BeginLifetimeScope())
{
var basket = scope.Resolve<IBasket>();
basket.AddToBasket(clickedItem);
scope.Dispose();
}
}
And here is my container / autofac setup:
public class App
{
public static IContainer Container { get; set; }
public App()
{
var builder = new ContainerBuilder();
builder.RegisterType<ProductList>().As<IProductList>();
builder.RegisterInstance(new Basket()).As<IBasket>();
Container = builder.Build();
}
}