1. Create your project (example is for windows forms) 2. Install from nuget: Autofac, Autofac.Integration.Mvc, EntityFramework. 3. Add references to: Nop.Core, Nop.Data, Nop.Services, Nop.Web.Framework (look update at the bottom). 4. ASP.NET MVC, ASP.NET Razor, ASP.NET Web Pages, Microsoft.Web.Infrastructure should be installed also. 5. Then go to your program.cs file and add:
using Nop.Core.Infrastructure;
6. Add in Main():
EngineContext.Initialize(false);
7. Go to your App.config file. Add: <section name="NopConfig" type="Nop.Core.Configuration.NopConfig, Nop.Core" requirePermission="false" /> in <configSections>. Add: <NopConfig> <DynamicDiscovery Enabled="true" /> <Engine Type="" /> <Themes basePath="~/Themes/" /> </NopConfig> after <configSections>.
Now EngineContext should initialize without exceptions. And so all services should register.
Then you use services like this anywhere in your program:
8. Forgot: You should also create App_Data folder and move settings.txt there to have access to your database.
Also update: Better add existing projects Nop.Core, Nop.Data, Nop.Services, Nop.Web.Framework and references to them in your program than just references to already compiled dll libraries because their compilation will also cause needed packages for them to be copied to debug/release directory. Without them EngineContext will not initialize.
Thanks for the useful tips. I'd add that if you want to use your own EF datacontext along with the NOP one you wont register it as you would with a plugin using RegisterPluginDataContext but :
//here is the registration for the NopObjectContext, this way you can avoid to rely on the settings.txt file and get the //connectionstring from somewhere else builder.Register<IDbContext>(c => new NopObjectContext(nopConnectionString)).InstancePerLifetimeScope();
//here is your datacontext registration builder.Register(c => new YourDataContext(nopConnectionString)).Named<IDbContext>("nop_object_context_your_name_here").InstancePerLifetimeScope();
//you can now register the repositories that will use your named datacontext builder.RegisterType<EfRepository<YourEntity>>().As<IRepository<YourEntity>>().WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_your_name_here")).InstancePerLifetimeScope();
Having trouble getting this to work. I think I'm close. I don't think it is finding the connection string because I am getting the following error: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.
This is coming from [STAThread] static void Main() { EngineContext.Initialize(false); IManufacturerService ms = EngineContext.Current.Resolve<IManufacturerService>();
Figured it out. For the MapPath was looking for the App_Data folder in my \bin\Debug\ folder of my windows forms app. I copied that App_Data folder to that directory and it works (I hope).
I think I found out a couple of nagging issues that I have. For one thing, you have to make sure your Windows Forms project is .Net 4.5.1. Second, if you get the error below, you may have to update System.Web.Mvc through NUGet (see: http://stackoverflow.com/questions/19491860/could-not-load-file-or-assembly-system-web-http-4-0-0-after-update-from-2012-to)
Additional information: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I am getting error on this line while following your procedure. "" EngineContext.Initialize(true); INewStoreService ps = EngineContext.Current.Resolve<INewStoreService>();""
The requested service 'Nop.Core.Data.DataSettings' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.