Writing Plugins vs Custom Libraries

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
I have a question about creating a custom library.  I've created a number of WHOLE MODULE ADDITIONS (ie: a store locator, a photo gallery, etc...)  I've created my own additional DATATABLES, SERVICES (BDLs), ADMIN MODULES, and of course, Front-End Views.

I have everything developed in Nop 2.2 and am in the process of upgrading everything to Nop 2.6.  Right now, I'm added my own Classes to the Nop.Core.Domain, updated the Nop.Data Library, and Added Several Entries to the Nop.Services Library.  Most, if not all, of this, is separate, additional code (I've strived greatly to only add custom code, and not modify any core Nop development.

I realize I can probably created a custom Data Access Plugin, for each module, but I am wondering if its not just easier to create my own Custom Library Set (the website is www.arknaturals.com - so I would create ARK. libraries).

To do this, would I essentially need to duplicate your Nop library structure?

Ark.Core (include my custom objects in Ark.Core.Domain)
Ark.Data - map to my objects only
Ark.Services - Put all my custom Service and Interface classes in there?

And which is the best way to go (Plugin or Custom Library Module)?  Not sure I totally understand the pros/cons of writing individual Plugins for each module, vs create an entire Custom Library set.

Thanks in advance!
11 years ago
This is a good question and one I struggled with a while back. The short answer is, weigh the amount of customization you require vs. the desire for easy upgrades.

I ran into your exact situation with a client who wanted a great deal of customization.  So much in fact that after initially trying the plugin route, I scrapped the whole thing and rebuilt the entire application using my own custom libraries.

What you need to understand is that to really be able to do this effectively and keep the core nop files up to date, you will really have to have a great understanding of the entire nop architecture, read the change set comments carefully, and do lots of testing.  If you can accept this then I highly recommend going this route if you indeed have a lot of custom tables and logic.

Typically I will only upgrade if there has been some core improvements, bug fixes, or new features my client will use.  Everything else I just let go.  NopCommerce is a fantastic platform to build just about any application on. IMHO.

Good luck.

t
11 years ago
Thanks so much for your reply.  I'm basically in the same exact position as you, and just spent a lot of time writing one or two plugins this week, but it seems like a lot of work for each module.

In regards to my specific question, do I need to create my own BLOCK of libraries if I want to go the custom library route?

So Nop has

Nop.Core
Nop.Data
Nop.Services

Do I (or should I) create my own library for each of these?

[Custom].Core
[Custom].Data
[Custom].Services

I can pretty easily duplicate the Nop structure and take out everything but my own custom code, but wanted to get confirmation of that if possible before I went down that road of extra work.

Thanks again for your time!

Greg
11 years ago
That's exactly what I did. MyClient.Core, MyClient.Data, MyClient.Services.  I had to go a bit further and change some the nop files as well, so that makes it a little harder to keep track of.  

However, if you are only adding your custom classes and logic then you only need to copy and paste when changes are made to nop files.  Good luck with your project and don't hesitate to ask for more help.

t
11 years ago
That's what I figured and I think that is a strategy I am good with going forward!  Thanks so much and I will hit this thread again for extra advice!

Best

Greg
11 years ago
This seems to be pretty common to each of us. I would like to request the NopTeam to have a look at this and suggest the best way. And if possible plan something that makes customizations easier to manage while upgrading to a newer versions.
11 years ago
Yes, I agree (although I dont think its their responsibility) to create a Core/Baseline Custom - library pack, that allows users to start creating their own libraries from scratch.

I've essentially done that myself.  I made copies of the Nop.Libraries and created my own Custom.Libraries.  Then I've been weeding out all the Nop related code bit by bit to create my own Core, Data, and Service libraries for my own objects moving forward.

I started building with Nop 1.9, then upgraded to 2.2.  A lot of my code is woven deep into the Nop core framework (though I did not change any of the core tables, only adding my own custom stand-alone objects).

With 2.6, I am finally separating ALL my code into separate core libraries and code to make future maintenance and migrations much more straight forward.

Even, a write up, like the ones that are posted about writing custom Plugins or Data Access Plugins, for building your own custom Library Group would be immensely helpful to the community.
11 years ago
Ok, I've spent the last day setup my own separate libraries:

[Custom].Core
[Custom].Data
[Custom].Services

I've moved most of my existing code from the Nop Libraries to my custom libraries.
I added my new Library group to my Nop 2.6 solution.

I updated my DependencyRegistrar so that the Services in my new libaries are registered.

However, I keep running into the same problem:  The dreaded No parameterless constructor defined for this object.

I have checked and double-checked the constructor and my services and everything I need has been included and updated.

Is there a problem with having 2 library blocks existing side-by-side in a Nop solution?
Can someone help me understand what the BASELINE code would be for my own custom Core, Data, and Services libraries (cuz honestly, unless you delete a whole lot of it, there is a tremendous amount of duplication and redundancy between the Custom and Nop libraries).  I am simply not sure what is and is not essential in a custom library group.

What I find almost incredible is there are literally NO BOARDS that discuss this coding direction.  There are tons of stuff about Plugins (understandable) but I can't believe many people (especially by v2.6) haven't aggressively tried to create their own library stacks to make the existing code more maintainable and easier to upgrade.  I find it simply incredible, and honestly, pretty frustrating.

Maybe someone out there can help! :)


Here is my error and stack:

No parameterless constructor defined for this object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[MissingMethodException: No parameterless constructor defined for this object.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67

[InvalidOperationException: An error occurred when trying to create a controller of type 'Nop.Web.Controllers.LocatorsController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +232
   System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
   System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970356
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
11 years ago
This error can be quite misleading.
It is often due to the fact that AutoFac (the dependency container) cannot resolve a dependency in the constructor of the object and therefore is looking for a parameterless constructor, which obviously C# does not include when you already have a constructor with parameters.
For example if you have:

public class MyController
{
   public MyController(IMyService myService)
   {

   }
}


and AutoFac cannot resolve IMyService, it will give you the error you are seeing.
Make sure that all your dependencies are registered.
Hopefully this will point you to the problem.
11 years ago
I dont understand your response.  If you read my post, you will see I already mention that I have updated, checked, and rechecked my DependencyRegistrar file to ensure that all my Services are registered.  So that is not the problem.  

I know after a while of building and upgrading my nop code that is an essential part of development with this framework, and can see that many people are unaware of that with all the posts on this issue.  

In fact, I haven't created any new code at all.  All I've done is separate old code into new libraries, update the namespaces and add/modify the registrations in my existing code.

Please read the details of a thread more carefully if you are going to post.

I am looking for an answer to my specific question regarding setting up multiple libraries side by side.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.