This project is read-only.

I need ninject! Deleting the NinjectWebCommon.cs not an option

Nov 25, 2013 at 8:54 AM
Edited Nov 25, 2013 at 9:02 AM
I have an MVC4 application and have been using ninject from the start and I need to continue using this. The NinjectWebCommon file is therefore essential so deleting as the installation suggests is not an option for me.

What suggestions do you have to resolve this?
Nov 25, 2013 at 9:34 AM
I suggest you delete it, as per the instructions, and then add whatever custom bindings/registrations you need Ninject for, using the IDependencyBuilder interface.

Take a look here for a sample: SampleSiteBuilder

Remember to add the builder to the web.config file, to the mvcForum/additionalBuilders section.
Nov 25, 2013 at 10:17 AM
I have done that and all builds so great so far.

I am now receving the following, any ideas? Is it the SimpleMembershipProvider causing the issue? If it is back to regular Asp.Net membership provider for my app.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: This method cannot be called during the application's pre-start initialization phase.

Source Error:

Line 42: <providers>
Line 43: <clear />
Line 44: <add name="ProviderWrapper" type="mvcForum.Web.Providers.MembershipProviderWrapper" WrappedProvider="simple" />
Line 45: <add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
Line 46: </providers>
Nov 25, 2013 at 10:48 AM
I have resolved that issue I had left the following in my config:
<add key="enableSimpleMembership" value="true" />
I have changed this to:
<add key="enableSimpleMembership" value="false" />
With the following:
    <clear />
    <add name="ProviderWrapper" type="mvcForum.Web.Providers.MembershipProviderWrapper"
         WrappedProvider="SqlMembershipProvider" />
    <add name="SqlMembershipProvider"
         passwordFormat="Hashed" />
But when the app starts now I receive the following error message below when AreaRegistration.RegisterAllAreas(); is called in the Application_Start().
Method not found: 'Void System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration1.Ignore(System.Linq.Expressions.Expression1<System.Func`2<!0,!!0>>)'.
Nov 25, 2013 at 10:58 AM
I have also resolved that as I hadn't added the Additional Builder correctly. This is now done and the application starts up.

I am now seeing a injection issue.

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.

I expect that it is becase I am inject a UnitOfWork into the Controller class and something isn't registering correctly with ninject. I will look into this but would appreciate any information you have to help as this would seem to be the final hurdle and I will have my existing application and all it's functionality with your excellent forum.
Nov 25, 2013 at 11:46 AM
You do call Initialize in the application_start method in global.asax ?

Mar 14, 2014 at 3:41 AM
Can I hop in on this thread? I have a mvc4 app as well and I am using ninject to handle the injection of the domain services into the controllers. I followed the steps above and am still quite a bit confused. Not sure how to name/setup the additional builder definitions in the web.config.

My goal is to create my mvc site with membership, etc. for users to login and store/modify/etc. various application type data ... but I want to offer a forum for free members, paid members, etc. that runs right along side my app.

Any help is appreceiated!
Mar 14, 2014 at 12:18 PM
Tak a look at the SampleSiteBuilder , you create your own class and let it implement the IDependencyBuilder interface. Then you add it to the mvcForum/additionalBuilders section in the web.config file.

You can name it whatever you want, just make sure to put in the correct type (regular format, full path to the class and name of the assembly).

Hope this helps.

You can download the MVC 5 demo site to take a look at how it works (put it in debug etc.).