0

I have develop web application in ASP.NET MVC using StructureMap DI pattern to retrieve data from BAL to UI and used layered architecture pattern to retrieve data from DAL to BAL. find bellow my class diagram.

See my class diagram

So,i tired to config StructureMap service register as

    public class Bootstrapper
    {
          public static void Initialize()
          {
              StructureMapConfiguration.AddRegistry(new ServiceRegistry());
          }
          public class ServiceRegistry : Registry
          {
              protected override void configure()
              {
                   ForRequestedType<IVehicleService> ().TheDefaultIsConcreteType<VehicleService>();
               }
          }
    }

But, configuration is not applied correctly, occurred errors and saying "some methods are not find in interface class". of course, its correct. because in my BAL class have inherited some of methods/function from DAL. So,please help me fix this issue or give any best practice to apply my project.

2 Answers 2

5

I recommend you reconsider the way your classes are organized, and try to apply the Dependency Inversion Principle. The way you've structured your classes, your UI project will depend on your BAL project, which will depend on your DAL project. You want your specific details of how you talk to your database (in the DAL) to depend on abstractions (in your BAL), not the other way around. You can achieve this easily by implementing the Onion Architecture (aka ports and adapters or hexagonal architecture). I have a brief online course covering converting from a traditional N-tier architecture (like yours) to this approach.

Also, I think you meant to use the Repository pattern, not Respiratory, in your class diagram. You can see a simple way to get started resolving dependencies using StructureMap in ASP.NET MVC 5 as well.

Once you have this architecture set up, things become very simple. If you name your interfaces consistently, you can use StructureMap's WithDefaultConventions() method to eliminate the need to register every concrete type to its associated interface. For instance, you could define IVehicleRepository (in your Core project) and its implementation VehicleRepository (in your Infrastructure project, which references Core). At that point, in your UI project where you configure StructureMap, your controllers can simply request an IVehicleRepository in their constructors, and StructureMap will fulfill such requests with your VehicleRepository implementation (unless you configure it to do otherwise).

0
1

Don't override the "configure()" method but do your registrations in a constructor for your Registry class.

It also appears you may be using an earlier version of StructureMap as the registration syntax is more terse in more recent versions.

There are great examples in the source code:

https://github.com/structuremap/structuremap/blob/master/src/StructureMap.Testing/Configuration/DSL/RegistryTester.cs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.