Custom 2.0 Installation Question

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi,

What would be the best approach to temporarily bypass the installation page and return to the "DropDatabaseOnChanges" method that some of the earlier commits were using?

This is only for playing and testing a few variations on your model for 2.0.  It's much easier to do this when you bypass the installation page.

Thanks.
12 years ago
For anyone who wants to play with the 2.0 model without having to reinstall the db or manually add tables here is what I did.

There are basically 3 steps to this process.

1. Work around the data provider classes in Nop.Web

In EfStartupTask.cs, you can comment out all existing code in the execute method and replace with the old code.
Database.SetInitializer<NopObjectContext>(new DatabaseInitializer());


Next you add the old file DatabaseInitializer.cs.  The key to this file is inheriting from DropCreateDatabaseIfModelChanges.  This is what looks up an EdmMetadata table in your database and compares the old model to the new one.  This is what makes making changes to the model much faster.  Don't forget to remove this when your done.
public class DatabaseInitializer : DropCreateDatabaseIfModelChanges<NopObjectContext>
    {
        protected override void Seed(NopObjectContext context)
        {
            EventBroker.Instance.OnInstallingDatabase(this, new EventArgs());

            base.Seed(context);
        }
    }


2. Remove the boolean parameter databaseInstalled from Nop.Core.Infrastructrue.EngineContext.Initialize

There are a few other references to this methods parameter in the Infrastructure folder that you will have to remove as well.  Just build Nop.Core and the errors will tell you where to go.  Takes 2 minutes.

3.  Place a reference to your connectionStrings.config in Nop.Web.Framework.DependencyRegistar

Using a connectionStrings.config file is the old nop way of doing things.  You won't need the Settings.txt file anymore.  Comment out all code under the '//data layer' comment and replace with this.
            builder.Register<IDbContext>(c => new NopObjectContext("NameOfMyConnString")).InstancePerHttpRequest();
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();


Don't forget to place a reference to connectionStrings.config in your web.config file.

4. I know, I said three steps.  The last step is in Global.asax.cs

Add this to Application_Start
            //subscribe to events
            EventBroker.Instance.InstallingDatabase += InstallDatabase;


Remove or comment out all references to "DataSettingsHelper.DatabaseIsInstalled()"

Add this method
protected void InstallDatabase(object sender, EventArgs e)
        {
            EngineContext.Current.Resolve<IInstallationService>().InstallData();
        }


And finally in Application_BeginRequest, comment out
EnsureDatabaseIsInstalled();


That's it.  Happy coding!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.