OrderService nop 2.x

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

Thank you for your advice. Many of the problems with the software have been solved.

I am now trying to use TaxCategoryService and CustomerService in my TaxProvider class. Here is the method:

public CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest)
{

//get tax class name, based on ID


//update customer information with validated address

}

Do I use IDependencyRegistrar somehow? The problem is that I'm calling this from a handler and I cannot adjust the constructor.

I am calling my tax provider in the EntityUpdated<Order> event like this:

    public class OrderUpdatedHandler : IConsumer<EntityUpdated<Order>>
    {

...

        public void HandleEvent(EntityUpdated<Order> eventMessage)
        {
          

            var order = eventMessage.Entity;

          

            if (order.OrderStatus == OrderStatus.Complete)
            {
              
                //TO DO: Insert TaxCategoryService into this method
                api.InsertTaxIntoAvalara(order);
          
            }
          

        }

I cannot adjust the constructor because then it won't implement the interface. Do you have any advice?



Actually adding a constructor will not break the interface. Consumers are wired up using dependency injection as well. As long as all the objects are correctly mapped in the dependency registrar your code should work just fine.
12 years ago
Hi,

OK, I got it all working. Here is the dependency class I created for my provider:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Core.Data;
using Autofac;
using System.Data.Entity;
using Nop.Core;
using Nop.Data;
using Nop.Plugin.Tax.AvalaraTax.Interfaces;

namespace Nop.Plugin.Tax.AvalaraTax
{
    public class AvalaraTaxDependencyRegistrar : IDependencyRegistrar
    {

        public int Order
        {
            get { return 0; }
        }

        public void Register(Autofac.ContainerBuilder builder, Core.Infrastructure.ITypeFinder typeFinder)
        {
            //I want to load AvalaraTaxProvider as a dependency.
            builder.RegisterType<AvalaraTaxProvider>().As<IAvalaraTaxProvider>();
        }

    }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.