I have a class library that called ServiceLayer which contains the below code:
IProductService.cs
public interface IProductService
{
void AddNewProduct(Product product);
IList<Product> GetAllProducts();
}
ProductService.cs
public class ProductService : IProductService
{
readonly IDbSet<Product> _products;
public ProductService(IUnitOfWork uow)
{
_products = uow.Set<Product>();
}
public void AddNewProduct(Product product)
{
_products.Add(product);
}
public IList<Product> GetAllProducts()
{
return _products.Include(x => x.Category).ToList();
}
}
I installed Structuremap.MVC5, so in DefaultRegistry
file i have the below code:
DefaultRegistry.cs
public DefaultRegistry()
{
Scan(
scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
For<IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use(() => new ApplicationDbContext());
}
But structure map doesn't work and gives me this exception:
An exception of type 'StructureMap.StructureMapConfigurationException' occurred in StructureMap.dll but was not handled in user code
Additional information: No default Instance is registered and cannot be automatically determined for type 'MEF.ServiceLayer.IProductService'
So my question is this, How can structure map scan another class library other then main project?