Share variables between projects

后端 未结 5 846
天命终不由人
天命终不由人 2021-01-05 22:04

I have a solution with some projects. One of this projects is the one I\'ve defined as main, also his class has a main Method.

Inside this class, I\'ve defined some

5条回答
  •  無奈伤痛
    2021-01-05 22:41

    Based on your comments to other answers it sounds like your problem is really that you have a circular dependency which you need to break. Generally the way to do that is to factor out an interface and place it in a third project that both other projects can reference so instead of

    class Foo //foo lives in project 1 (depends on project 2)
    {
        public Bar GetNewBar()
        {
            return new Bar(this);
        }
        public void DoSomething(){}
    }
    
    public class Bar //bar lives in project 2 (depends on project 1 -- cant do this)
    {
        public Bar(Foo parent){}
    }
    

    you have

    class Foo: IFoo //foo lives in project 1 (depends on project 2 and 3)
    {
        public Bar GetNewBar()
        {
            return new Bar(this);
        }
        public void DoSomething(){}
    }
    
    public class Bar //bar lives in project 2 (depends on project 3)
    {
        public Bar(IFoo parent){}
    }
    
    public interface IFoo //IFoo lives in project 3 (depends on nothing)
    {
        void DoSomething();
    }
    

提交回复
热议问题