Search code examples
c#unit-testingdependency-injectionspring.net

Programmatical "Spring.Net" Configuration


I have started work on a project which uses Spring.Net, and i'm coming at it from a Unity background. I'm trying to set up an integration test for part of the solution, and need to setup Spring to build all my classes on demand. I don't want to use configuration files.

I want to do the following:

  • Register My Types

  • Configure the root instance

  • Have all types populated when I pull them from the container

I've populated my types (Including mocks) in the container, and configured my root instance, but no types get populated. There don't appear to be any attributes to specify what I want, and type mappings are done by string names.

I was looking at building up a MutablePropertyValues collection, but they only seem to take instances of the class I want to populate, rather than a reference, which breaks lazy loading. Is there a reference type class I can use?

Appologies if this is a bit vague, but I know what I want to achieve, and am unsure as to what the best way to achieve it would be.


Solution

  • For configuring Spring .NET using code you can use the CodeConfig project- http://www.springframework.net/codeconfig/index.html

    How do you run your tests? You can inherit from AbstractDependencyInjectionSpringContextTests and your classes will be loaded from the container. More info here - http://www.springframework.net/doc-latest/reference/html/testing.html