1

我的客户问我一些看起来我做起来很简单的事情。他有 nopcommerce 1.9 网站,他希望开发一个简单的 windows 窗体应用程序来修改客户地址。所以我尝试配置一个新闻窗口窗体项目:

static void Main(string[] args)
{
    // Code that runs on application startup
    NopConfig.Init();

    //initialize IoC
    IoC.InitializeWith(new DependencyResolverFactory());

    //initialize task manager
    TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
        TaskManager.Instance.Start();

        //open
        new FormClient().Show();

        TaskManager.Instance.Stop();
    }

然后我创建了一个公开数据的服务管理器:

public class ServiceManager
{
    public ICustomerService CustomerService;

    public ServiceManager()
    {
        var dbContext = IoC.Resolve<NopObjectContext>();
        CustomerService = new CustomerService(dbContext);
    }

}

并且无法访问CustomerService 方法,因为 resolve 方法找不到要实例化的具体类NopObjectContext

(您可以在此位置找到 nop commerce 1.9:http: //nopcommerce.codeplex.com/downloads/get/176949

4

1 回答 1

1

最后,它起作用了:

App.config 必须是:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="NopConfig" type="NopSolutions.NopCommerce.BusinessLogic.Configuration.NopConfig, Nop.BusinessLogic" requirePermission="false"/>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="NopSolutions.NopCommerce.BusinessLogic.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>

  </configSections>
  <appSettings>
    <add key="dependencyResolverTypeName" value="NopSolutions.NopCommerce.BusinessLogic.Infrastructure.UnityDependencyResolver, Nop.BusinessLogic" />
  </appSettings>
  <connectionStrings>
    <add name="NopEntities" connectionString="metadata=res://*/Data.NopModel.csdl|res://*/Data.NopModel.ssdl|res://*/Data.NopModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=EGG-BANKS;Initial Catalog=nopvierge2;Persist Security Info=True;User ID=sa;Password=sqlserver;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="NopSqlConnection" connectionString="Data Source=DAVID-TOSH\SQLEXPRESS;Initial Catalog=nop;Integrated Security=True;Persist Security Info=False;MultipleActiveResultSets=True;Connect Timeout=120" />

  </connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
  <applicationSettings>
    <NopSolutions.NopCommerce.BusinessLogic.Properties.Settings>
      <setting name="Nop_BusinessLogic_Clickatell_PushServerWS" serializeAs="String">
        <value>http://api.clickatell.com/soap/webservice_vs.php</value>
      </setting>
      <setting name="Nop_BusinessLogic_EuropaCheckVatService_checkVatService" serializeAs="String">
        <value>http://ec.europa.eu/taxation_customs/vies/services/checkVatService</value>
      </setting>
    </NopSolutions.NopCommerce.BusinessLogic.Properties.Settings>
  </applicationSettings>

  <NopConfig>
    <SqlServer ConnectionStringName="NopSqlConnection"/>
    <ScheduleTasks>
      <Thread seconds="60">
        <!--do NOT enable ClearCache task if you have enabled tracking online users-->
        <task name="ClearCache" type="NopSolutions.NopCommerce.BusinessLogic.Caching.ClearCacheTask, Nop.BusinessLogic" enabled="false" stopOnError="false"/>
        <task name="PurgeOnlineUsers" type="NopSolutions.NopCommerce.BusinessLogic.Audit.UsersOnline.PurgeOnlineUsersTask, Nop.BusinessLogic" enabled="true" stopOnError="false"/>
        <task name="Emails" type="NopSolutions.NopCommerce.BusinessLogic.Messages.SendQueuedMessagesTask, Nop.BusinessLogic" enabled="true" stopOnError="false" maxTries="5"/>
        <task name="KeepAlive" type="NopSolutions.NopCommerce.BusinessLogic.Utils.KeepAliveTask, Nop.BusinessLogic" enabled="true" stopOnError="false" path="keepalive/ping.ashx"/>
      </Thread>
      <Thread seconds="600">
        <task name="DeleteExpiredCustomerSessions" type="NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.DeleteExpiredCustomerSessionsTask, Nop.BusinessLogic" enabled="true" stopOnError="false" deleteExpiredCustomerSessionsOlderThanMinutes="43200"/>
        <task name="DeleteExpiredShoppingCarts" type="NopSolutions.NopCommerce.BusinessLogic.Orders.DeleteExpiredShoppingCartsTask, Nop.BusinessLogic" enabled="false" stopOnError="false" deleteExpiredShoppingCartsOlderThanMinutes="259200"/>
      </Thread>
      <Thread seconds="60">
        <task name="UpdateExchangeRates" type="NopSolutions.NopCommerce.BusinessLogic.Directory.ExchangeRates.UpdateExchangeRateTask, Nop.BusinessLogic" enabled="true" stopOnError="false"/>
      </Thread>
      <Thread seconds="3600">
        <task name="DatabaseMaintance" type="NopSolutions.NopCommerce.BusinessLogic.Maintenance.DatabaseMaintanceTask, Nop.BusinessLogic" enabled="false" stopOnError="false"/>
      </Thread>
    </ScheduleTasks>
  </NopConfig>
</configuration>

使用 program.cs 文件:

    static void Main(string[] args)
    {

        // Code that runs on application startup
        NopConfig.Init();

        //initialize IoC
        IoC.InitializeWith(new DependencyResolverFactory());

        //initialize task manager
        TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
        TaskManager.Instance.Start();

        new form1().show();

        TaskManager.Instance.Stop();
    }
于 2012-06-03T07:55:35.703 回答