Error converting order processing sys from VB.Net to C#

Oct 10, 2009 at 8:27 AM

Hi. I have converted Order Processing System from VB.Net to C#. When i run the application and click on Order tab it gives an error

 

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily ACompany.OrderProcessing.Infrastructure.IUnitOfWork, ACompany.OrderProcessing.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

"StructureMap Exception Code:  202

No Default Instance defined for PluginFamily ACompany.OrderProcessing.Infrastructure.IUnitOfWork, ACompany.OrderProcessing.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null "

i think the problem exists in function of BootStrapper Class.

"public static void ConfigureStructureMap()

    {        ObjectFactory.Initialize(x =>  {        x.AddRegistry(new ServiceRegistry());  }   );

    }"

Similar function in VB.Net works fine
" Public Shared Sub ConfigureStructureMap()
        ObjectFactory.Initialize(AddressOf ConfigStructureMap)
    End Sub
    Private Shared Sub ConfigStructureMap(ByVal x As IInitializationExpression)
        x.AddRegistry(New ServiceRegistry)
    End Sub"

 

Coordinator
Oct 11, 2009 at 1:14 PM

Hi usmanigbal,

What does your ServiceRegistry class look like? It should look like the below:

public
class ServiceRegistry : StructureMap.Configuration.DSL.Registry
    {
        public ServiceRegistry()
        {
             ForRequestedType<IProductRepository>()
                .TheDefaultIsConcreteType<NhibernateRepository.ProductRepository>();

            ForRequestedType<IOrderRepository>()
               .TheDefaultIsConcreteType<NhibernateRepository.OrderRepository>();

            ForRequestedType<ICustomerRepository>()
               .TheDefaultIsConcreteType<NhibernateRepository.CustomerRepository>();

            ForRequestedType<ICustomerService>()
               .TheDefaultIsConcreteType<Services.CustomerService>();

            ForRequestedType<IProductService>()
               .TheDefaultIsConcreteType<Services.ProductService>();

            ForRequestedType<IOrderService>()
               .TheDefaultIsConcreteType<Services.OrderService>();

            ForRequestedType<IUnitOfWork>()
               .TheDefaultIsConcreteType<NhibernateRepository.NhibernateUnitOfWork>();
        }
    }      

This class lets structuremap know what concrete types you want to use for all of the service dependencies.

Hope this helps, let me know if you need anymore help.

Cheers
Scott