I have following code written on top of Microsoft Unity. This is the implementation of property injection. I recently gone through a Bridge Design Pattern that separates abstraction from implementation by object composition at runtime.

Abstraction: AbstractOperation which implements IOperation

RefinedAbstraction: SubstractOperation

ImplementorInterface: ILogger

ConcreteImplementation: ConsoleLogger

Is Unity-Container's Property Injection following the Bridge Design Pattern by default?

    static void Main(string[] args)
        var program = new Program();
        unityContainer = new UnityContainer();

        unityContainer.RegisterType<IOperation, Unity.SubstractOperation>("-");

        var currentOperation = unityContainer.Resolve<IOperation>("*");
        currentOperation.logger.Info($"{nameof(SubtractOperation)} | Begin");

        currentOperation.DoIt(3, 2);

        Console.WriteLine(opera.Print(3, 2));
        currentOperation.logger.Info($"{nameof(SubtractOperation)} | End");

    public interface ILogger
        void Info(string message);
        void Error(string message, Exception ex);

    public interface IOperation
        ILogger logger { get; set; }
        int DoIt(int number01, int number02);
        string Print(int number01, int number02);

    abstract class AbstractOperation : IOperation
        private ILogger _logger { get; set; }

        public ILogger logger
            get { return _logger; }
            set { _logger = value; }

        public AbstractOperation()

        public abstract int DoIt(int number01, int number02);

        public virtual string PrintPretty(string operatorType, int number01, int number02, int result) => $"{number01} {operatorType} {number02} = {result}";

        public abstract string Print(int number01, int number02);

    class SubtractOperation : AbstractOperation
        int result = 0;

        public override int DoIt(int number01, int number02) => result = number01 - number02;

        public override string Print(int number01, int number02) => base.PrintPretty("-", number01, number02, result);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.