Yes, and i've carefully debugged through the instance creation process.
With the old version, where the constructor parameters for the Plugin class were concrete classes instead of interfaces (not registered in Autofac) the error was happening here:
public object ResolveUnregistered(Type type)
{
var constructors = type.GetConstructors();
foreach (var constructor in constructors)
{
try
{
var parameters = constructor.GetParameters();
var parameterInstances = new List<object>();
foreach (var parameter in parameters)
{
var service = Resolve(parameter.ParameterType);
if (service == null) throw new NopException("Unkown dependency");
parameterInstances.Add(service);
}
return Activator.CreateInstance(type, parameterInstances.ToArray());
}
catch (NopException)
{
}
}
throw new NopException("No contructor was found that had all the dependencies satisfied.");
}
As you can see, he walks through the constructor parameters and try to resolve them, then asks for the Activator to create an instance at runtime providing the constructor parameters.
Now all this proceeds well, so the thing get past this line:
var plugin = pluginDescriptor.Instance() as FavoriteCategoriesPlugin;
Instead, the plugin code hangs there:
if (plugin.AddFavoriteCategories(order.Id))
with a NullReferenceException. Taking a peek at the code from AddFavoriteCategories it is pretty obvious why :)
public bool AddFavoriteCategories(int orderId)
{
Order order = _orderService.GetOrderById(orderId);
IList<Order> orders = null;
orders.Add(order);
return _favoriteCategoriesService.AddFavoriteCategories(orders);
}
You have to initialize the list with new List<order>() or else it will cast the Exception.
If you debug from this you should be fine!
Let us know how it's going