1

I am unsure the right way to do this. here is a simple representation of what I am trying to do, I will explain in a second step why I am doing this.

Two objects A and B need to be injected into class myClass. A can be injected with no parameters, fine. Then B needs to be created with a reference to A. How do I do that in spring?

the reason I am doing this is Entity Framework - I have a context object that is required in my service layer (persistence,..). My repository layers (DAL) need this paraneter passed in constructor to be created so they can access the DB. At the end of the service layer procedure, I need to be able to access my context object to save the transaction. Since I want to be able to mock the whole thing, i want both objects to be injected.

4

1 回答 1

0

Works using public object GetObject( string name, object[] arguments)

//_uow is my object containing my CONTEXT (DB ACCESS)
 _configRepo = (ICMConfigurationKVRepo)ContextRegistry.GetContext().GetObject("SLayer_IConfigurationKVRepo",new object[] { _uow });

Spring configuration:

<object name="SLayer_IConfigurationKVRepo" 
        type="xxx.Repository.ConfigurationKVRepo, Repository" 
        autowire="constructor">
于 2013-08-23T13:49:42.170 回答