How to invoke Custom Controller

Aug 29, 2012 at 6:13 AM

01. Product Domain Class has been created as below

   public class Product




       public int ProductID { get; set; }


       public Category Category { get; set; }


       public string ProductName { get; set; }


       public int Quantity { get; set; }


02. ProductRepository has been created as below


   public class ProductRepository : AbstractFactoryAndRepository


       #region Injected Services

       // This region should contain properties to hold references to any services required by the

       // object. Use the 'injs' shortcut to add a new service.




       #region Product (Action)

       [MemberOrder(Sequence = "1")]

       public Product CreateNewProduct()


           return Container.NewTransientInstance<Product>();



       // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.



03. ProductRepository has been registered in MenuServices (RunWeb)

04. ProductController has been created as below

public class ProductController : CustomController


       #region Injected Services

       public ProductRepository ProductRepository { set; protected get; }



       public ActionResult Index()


           Product prod = ProductRepository.FlightSearch();


           return View(prod);



05. Product folder has been created in Views and ObjectView.aspx and ObjectView.cshtml have been copied to product folder.

06. ObjectView.aspx has been customized a little bit.


Still generic view is displayed.

But customized view did not display and action of custom controller (ProductController) did not invoke.


Is there anything that I am missing?

Aug 29, 2012 at 8:32 AM

Well the short answer is that you probably haven't sorted out the routing.  This is explained in the Naked Objects manual under Custom Controllers, but is also a standard feature of ASP.NET MVC development.

However, let me take the opportunity to express concern.  Naked Objects is brilliant for applications where the generic user interface is suitable;  it is also really easy to customize views.  In extremis, you can customize controllers for specific operations.  But Naked Objects is not well suited at all to building fully-customized applications  i.e. where you want all (or most) Views and Controllers to be custom.  It is possible, but it is hard work.  You will find that any advantages from using Naked Objects (for example the automatic validation) are quickly out-weighed by the complexity of trying to get custom controllers to interwork with Naked Objects  -  all too soon you will end up feeling that you are 'fighting the framework'.

Furthermore, to get this approach to work, you will need to be fluent in writing conventional ASP.NET MVC applications.  The fact that you had not picked up the need to modify the routing does cause me to question whether that is the case. It is almost certainly quicker and easier to use only the standard patterns of ASP.NET MVC, than to try to create a hybrid.

I refer you to my answer to your previous posting.  If you want to write a fully custom app and you want to use the same domain model (unmodified) as will also work with Naked Objects MVC, then I recommend two options:

- Write a conventional ASP.NET MVC run project that does not use Naked Objects (per your previous posting), and work with the domain model via the conventional entity framework approach (i.e. with a DbContext). You will need to create your own implementation of the IDomainObjectContext, and I referred you to a previous discussion thread about this.

- Use Restful Objects for .NET, and build a completely custom application (either as a single page app, or as an ASP.NET MVC app) that talks to the Restful Objects API  -  where you will then get the fully benefit of the Naked Objects framework running under the covers.

Finally, may I ask that whenever I  -  or anyone else  -  answers one of your postings, that as a courtesy you indicate that you have read and understood the answer and how, if at all, you are going to act on it, before posting a different question. Thanks.

Aug 30, 2012 at 4:32 AM

Noted your points. Sorry to post this topic in separate thread. It should be posted in my previous post. bcoz it is related to that.

I found Naked Objects Framework is an excellent framework for rapid application development using DDD. In my case, 15-20% view need to customized. that's why, I do not want to write my own implementation of the IDomainObjectContext right now and also Restful Objects for .NET is a beta version and worked with ASP.NET MVC4.

Right now, I am working on customized view and customized controller. After that I'll work on Restful Objects for .Net