1

I have a class (named A) which uses another class (named B) as one of it's constructor's arguments by Opennetcf's IoC Dependency Injection.

the problem is when my application starts , class B's constructor is called twice.

Class A's constructor :

[InjectionConstructor]
public MyService([CreateNew]ClassB classb)
{
    _classb = classb;
}

I also load Class B by the "Load" method in the RootWorkItem collection.

any helps appreciated

  • 1
    I would strongly advice not to use attributes, because this hard codes the construction of the dependencies and creates a coupling to the container itself. Class `A` should not care whether it gets a new `B` or a reused object. When `A` really always needs a new instance of `B`, you should be using a `IBFactory` anyway, since `B` is probably not a service. I don't know whether your IOC container supports attribute-less injection, but I think it is better to switch to another framework when it doesn't. – Steven Aug 04 '11 at 07:19

1 Answers1

0

I dont know this IoC Framework but your'e telling it that a object must be injected by the framework and you also state that the ClassB class needs to be created. So maybe that cause class b constructor to be called twice ? Once with the injector attribite and once with the createNew Attribute

Wombat
  • 172
  • 3
  • 10