3

I have the following classes declaration : Logger Service,FacadeReaderService and BusinessManager. I want to inject Logger Service and FacadeReaderService in BusinessManager using Unity XML configuration.

Logger Service

public class LoggerService : ILoggerService
{

}

FacadeReaderService

public class FacadeReaderService : IFacadeReaderService
{
}

BusinessManager

public class BusinessManager : IBal
    {
        IFacadeReaderService _facadeReaderService;
        ILoggerService _loggerService;

        public BusinessManager(IFacadeReaderService facadeReaderService, ILoggerService loggerService)
        {
            this._facadeReaderService = facadeReaderService;
            this._loggerService = loggerService;
        }
    }

My question is how to inject this complex objects in my BusinessManager class ? Below is what I have done so far in my Unity Config file :

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <typeAliases>
    <typeAlias alias="IFacadeReaderService" type="Interfaces.Services.IFacadeReaderService, Interfaces" />
    <typeAlias alias="FacadeReaderService" type="Services.FacadeReader.FacadeReaderService, Services" />

    <typeAlias alias="ILoggerService" type="Interfaces.Services.ILoggerService, Interfaces" />
    <typeAlias alias="LoggerService" type="Services.Log.LoggerService, Services" />


    <typeAlias alias="IBal" type="Interfaces.Bal.IBal, Interfaces" />
    <typeAlias alias="BusinessManager" type="Bal.BusinessManager, Bal" />


  </typeAliases>
    <container>
      <register type="IFacadeReaderService" mapTo="FacadeReaderService" name="FRS"/>
      <register type="ILoggerService" mapTo="LoggerService" name="LS"/>
      <register type="IBal" mapTo="BusinessManager" name="BMS">
      <constructor>
        <param name="facadeReaderService" value="????????" />
        <param name="loggerService" value="??????" />
      </constructor>
      </register>
    </container>
</unity>

1 Answer 1

3

Well, I found the answer to my question by looking in Microsoft documentation : https://msdn.microsoft.com/en-us/library/ff660914(v=pandp.20).aspx#config_value

I will post the unity config, just in case there is someone who will need it :

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <typeAliases>
    <typeAlias alias="IFacadeReaderService" type="Interfaces.Services.IFacadeReaderService, Interfaces" />
    <typeAlias alias="FacadeReaderService" type="Services.FacadeReader.FacadeReaderService, Services" />

    <typeAlias alias="ILoggerService" type="Interfaces.Services.ILoggerService, Interfaces" />
    <typeAlias alias="LoggerService" type="Services.Log.LoggerService, Services" />


    <typeAlias alias="IBal" type="Interfaces.Bal.IBal, Interfaces" />
    <typeAlias alias="BusinessManager" type="Bal.BusinessManager, Bal" />


  </typeAliases>
    <container>
      <register type="IFacadeReaderService" mapTo="FacadeReaderService" name="FRS"/>
      <register type="ILoggerService" mapTo="LoggerService" name="LS"/>
      <register type="IBal" mapTo="BusinessManager" name="BMS">
        <constructor>
          <param name="facadeReaderService">
            <dependency name="FRS" />
          </param>
          <param name="loggerService">
            <dependency name="LS" />
          </param>
        </constructor>
      </register>
    </container>
</unity>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.