681 users online

Create new instance of _orderService

1 2 Next
Posted: 3 months ago Quote
Hi,

I'm trying to create an instance of _orderService within a WPF application I'm building to handle picking and packing.

I've added

nop.core
nop.data
nop.services
nop.web.framework

as references. I've added namespaces

using Nop.Core;
using Nop.Data;
using Nop.Services;
using Nop.Services.Orders;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Payments;

In my method I've got the code

this.lstbxOrders.ItemsSource = _orderService.SearchOrders(null, null, orderStatus, paymentStatus, shippingStatus, "", "", 0, 1000);

Intellisense is fine with this but when I run the code it complains because _orderService is null.

Can anyone tell me how to create this object? My C# is not very good.

Thanks

Darren Pegram
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
Do you ever instantiate _orderService?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
Posted: 3 months ago Quote
Hi, Thanks for getting back to me!

I've tried

  
OrderService orderService = new OrderService();


but obviously get the error

Nop.Services.Orders.OrderService' does not contain a constructor that takes 0 arguments  


so I tried

  OrderService orderService = new OrderService(_orderRepository,_opvRepository, _orderNoteRepository, _pvRepository, _recurringPaymentRepository, _recurringPaymentHistoryRepository, _customerRepository, _returnRequestRepository, _eventPublisher);


but now get the error

cannot convert from 'Nop.Core.Data.IRepository<WpfApplication3.Order>' to 'Nop.Core.Data.IRepository<Nop.Core.Domain.Orders.Order>'

Would I be able to PM you the full script. Any help is massively appreciated. I'm hoping to share the app once its completed.

Thanks

Darren Pegram
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
You need to pass in all of the services that OrderService expects.  They all have to be instantiated before you pass them which also requires that they have their dependencies instantiated and passed.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
Posted: 3 months ago Quote
AndyMcKenna wrote:
You need to pass in all of the services that OrderService expects.  They all have to be instantiated before you pass them which also requires that they have their dependencies instantiated and passed.


Any chance you coud do me an example?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
As it turns out, the OrderService really just wants repositories and EventPublisher.  When I was trying this it was with WorkflowMessageService which wanted ~10 other services :)

IRepository<Order> orderRepository,
IRepository<OrderProductVariant> opvRepository,
IRepository<OrderNote> orderNoteRepository,
IRepository<ProductVariant> pvRepository,
IRepository<RecurringPayment> recurringPaymentRepository,
IRepository<RecurringPaymentHistory> recurringPaymentHistoryRepository,
IRepository<Customer> customerRepository,
IRepository<ReturnRequest> returnRequestRepository,
IEventPublisher eventPublisher


The problem you were having is you're trying to pass a repository of your own Order object instead of the Nop.Core.Domain.Orders version.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
Posted: 3 months ago Quote
OK. I'm now instantiating the object. However, I'm not assigning anything to the repository variables so they are null when orderService.SearchOrders is called.

Here is my code (the important bit anyway)


...
using Nop.Core;
using Nop.Data;
using Nop.Services;
using Nop.Services.Orders;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Payments;
using Nop.Core.Data;
using Nop.Core.Events;



namespace WpfApplication3
{

    public partial class MainWindow : Window
    {
        private readonly IOrderProcessingService _orderProcessingService;
        private readonly IOrderService _orderService;

        private readonly IRepository<Order> _orderRepository;
        private readonly IRepository<OrderProductVariant> _opvRepository;
        private readonly IRepository<OrderNote> _orderNoteRepository;
        private readonly IRepository<ProductVariant> _pvRepository;
        private readonly IRepository<RecurringPayment> _recurringPaymentRepository;
        private readonly IRepository<RecurringPaymentHistory> _recurringPaymentHistoryRepository;
        private readonly IRepository<Customer> _customerRepository;
        private readonly IRepository<ReturnRequest> _returnRequestRepository;
        private readonly IEventPublisher _eventPublisher;

        public MainWindow()
        {
            InitializeComponent();
         }
              

      

       protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
                          
            OrderStatus? orderStatus = (OrderStatus?)(20);
            PaymentStatus? paymentStatus = (PaymentStatus?)(30);
            ShippingStatus? shippingStatus = (ShippingStatus?)(20);


          OrderService orderService = new OrderService(_orderRepository,_opvRepository, _orderNoteRepository, _pvRepository, _recurringPaymentRepository, _recurringPaymentHistoryRepository, _customerRepository, _returnRequestRepository, _eventPublisher);

          this.lstbxOrders.ItemsSource = orderService.SearchOrders(null, null, orderStatus, paymentStatus, shippingStatus, "", "", 0, 1000);

        }



What do I need to assign to each of the repository varaible.

private readonly IRepository<Order> _orderRepository = ????;

Thanks again for your help. I'll be waiting with bated breath making good use of f5
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
-Declare and instantiate a new DbContext object ( it will need your connection string )
-Create an EfRepository<T> for each entity and pass in in the DbContext
-Pass the repositories to the Order service

I think that will work.
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
Posted: 3 months ago Quote
AndyMcKenna wrote:
-Declare and instantiate a new DbContext object ( it will need your connection string )
-Create an EfRepository<T> for each entity and pass in in the DbContext
-Pass the repositories to the Order service

I think that will work.


Thanks for this. I'm desperate to ask you for sample code but I'm going to try and figure it out over the weekend myself.

Cheers

Darren
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
wunpac wrote:
-Declare and instantiate a new DbContext object ( it will need your connection string )
-Create an EfRepository<T> for each entity and pass in in the DbContext
-Pass the repositories to the Order service

I think that will work.

Thanks for this. I'm desperate to ask you for sample code but I'm going to try and figure it out over the weekend myself.

Cheers

Darren




Nop.Data.NopObjectContext dbContext = new Data.NopObjectContext("MY_CONNECTIONSTRING");
Nop.Data.EfRepository<Nop.Core.Domain.Orders.Order> orderRepository = new Data.EfRepository<Core.Domain.Orders.Order>(dbContext);
//repeat the above line for each object needed by the Order Service

Nop.Core.Events.SubscriptionService subscriptionService = new Core.Events.SubscriptionService();
Nop.Core.Events.EventPublisher eventPublisher = new Core.Events.EventPublisher(subscriptionService);

Nop.Services.Orders.OrderService orderService = new Orders.OrderService(orderRepository, restOfTheRepositories, eventPublisher);
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
1 2 Next