Dependancy issue

(Steve Smith) #1

Hey, currently prototyping nservicebus using an existing app. app is .NET4.5.2 console app.

I have the following code in my program.cs file.

IUnityContainer container = new UnityContainer();

        container.RegisterType(typeof(IGenericHttpRequestRepository<>), typeof(GenericHttpRequestRepository<>), new TransientLifetimeManager());
        container.RegisterType<IOrderRepository, OrderRepository>();
        container.RegisterType<IShipmentRepository, ShipmentRepository>();
        container.RegisterType<IOrderProcessService, OrderProcessService>();
        container.RegisterType<IShipmentService, ShipmentService>();
        var orderProcessService = container.Resolve<IOrderProcessService>();
        var shipmentService = container.Resolve<IShipmentService>();

        var endpointConfiguration = new EndpointConfiguration("NSB.ChannelAdvisorService");
        var transport = endpointConfiguration.UseTransport<LearningTransport>();

            customizations: customizations =>

        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

which unfortunately gives me an error when it trys to start the endpoint

The current type, NServiceBus.IEndpointInstance, is an interface and cannot be constructed. Are you missing a type mapping?

I have a service class that i wish to send a command message from.

public async Task PostNewOrderBatch()
        var list = _orderRepository.GetBatchedOrders();
        foreach(var item in list)// parallel this?
            await _endpoint.Send(item.ToObject<ProcessBatchOrdersCommand>()).ConfigureAwait(false);

what am i missing here?

(Daniel Marbach) #2

Hi Steve,

The endpoint instance is not automatically registered in the container.

The endpoint instance is returned on Endpoint.Start. You need to register that as a binding on the container.

See the note on our documentation page

Sorry if this caused any inconvenience. Please let us know how we could improve the documentation if things are not clearly spelled out on our doco page.