I have controller class ProductController.cs
namespace AmazonProductAdvertisingAPI.WebUI.Controllers
{
public class ProductController : Controller
{
private string _title = "Bible";
private IProductCollection _productCollection;
public int pageSize = 13;
public ProductController(IProductCollection productCollection)
{
_productCollection = productCollection;
}
public string Title
{
get
{
return _title;
}
set
{
_title = value;
}
}
// GET: Product
public ActionResult List(int page = 1)
{
return View(_productCollection.Products
.OrderBy(product => product.Title)
.Skip((page - 1)*pageSize)
.Take(pageSize)
);
}
}
}
class NinjectDependencyResolver.cs
namespace AmazonProductAdvertisingAPI.WebUI.Infrastructure
{
public class NinjectDependencyResolver : IDependencyResolver
{
private IKernel kernel;
public NinjectDependencyResolver(IKernel kernelParam)
{
kernel = kernelParam;
AddBindings();
}
public object GetService(Type serviceType)
{
return kernel.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return kernel.GetAll(serviceType);
}
private void AddBindings()
{
// Create dependency here
kernel.Bind<IProductCollection>().To<AmazonProductCollection>()
.WithConstructorArgument("title", "Bible");
}
}
}
Now in method AddBindings() of NinjectDependencyResolver.cs constructor argument is hardcoded. I want read Title attribute and put to
private void AddBindings()
{
// Create dependency here
kernel.Bind<IProductCollection>().To<AmazonProductCollection>()
.WithConstructorArgument("title", "here_must_be_Title_field_from_ProductController");
}
I plan set this field value when user fill search Input and click to button "Search".
Can somebody help and answer how better to do that NinjectDependencyResolver can get value from ProductController?