0

Some members of our devteam just spent some time debugging a similar issue.

A RegisterAs class used in one of our unittests has a public member: public List Mails { get; set; }

When this class is resolved through Funq, the member is set to null, even though it is was set in the constructor.

Our teammembers agree that it is wierd that this member is set to null by Funq, when the member isnt of a type that is registered as a Container.RegisterAs<>.

We are currently using ServiceStack version 4.0.33

It would have been nice to be able to configure ServiceStack.Funq to not touch public members if they dont implement an Interface thats Registered in Funq.

Markus Foss
  • 335
  • 4
  • 14

1 Answers1

1

The AutoWiring in ServiceStack's IOC uses a pre-compiled expression to populate all public instance properties. At the time the static factory is created it doesn't know all the registered dependencies that exist yet so the factory that's created, autowires each public writable property.

When you want different behavior you can use your own factory, e.g:

container.Register<IDependency>(c => new Dependency(c.Resolve<IFoo>()) {
        Bar = c.Resolve<IBar>()
    })
mythz
  • 141,670
  • 29
  • 246
  • 390