I’m a Java developer being forced to learn C#. Since I couldn’t stand NOT using a Dependency Injection container, I’m trying to configure Spring.NET in my project.
My project is divided into two solutions in Visual Studio: a ClassLibrary solution for all my business logic, services, DAOs, etc, and a Webapp section (ASP.NET pages, etc).
I found it interesting that I could effectively inject a dependency into an actual page via its code-behind, which I couldn’t really do with a JSP. However, what I’m wanting is to inject a service (UserService) from the ClassLibrary solution into the Login.aspx.cs, which is in the Webapp section.
Do I have to define the UserService object in both the App.Config on the ClassLibrary side AND on the Web.Config side?
No. You can import a Spring.Net configuration from the DLL project (defining the UserService) into the web project by using the ‘assembly’ prefix (works like ‘classpath’ prefix in Java). In your web project’s spring config you can then reference all objects defined in the DLL.
Don’t forget to mark your XML file containing the configuration (in the DLL project) as a resource to be included in the DLL.