aagocs
aagocs

Reputation: 1

Is there any way to compile multiple C# files in to multiple assembly with circular dependency?

I got for example two classes cross referencing each other. I want to compile these files to separate dll files.

File 1:

public class A
{
    public B bObj;

    public A () 
    {
        bObj = new B (this);
    }

    public void TestMethod()
    {

    }
}

File 2:

public class B 
{
    public B (A aObj)
    {
        aObj.TestMethod ();
        aObj.bObj.CallMyself ();
    }

    public void CallMyself()
    {

    }
}

I want to be able to share only the parts of the project with other people that they are working on. They need to be able to test it out, so they have to compile to project. Is there any magic solution that can be easily automated? The solution should work on any file, I know how to resolve circular dependency with a 3rd assembly.

As I mentioned, I know how to resolve a situation like this. I just wrote a nasty example, to show that I want to create a solution that can deal with any code.

Upvotes: 0

Views: 114

Answers (2)

Ashley Frieze
Ashley Frieze

Reputation: 5443

The short answer is don't do this. In this situation, it's common to put common interfaces in a separate library that everyone can see, so they can program to those interfaces without affecting each other, and then put the private stuff in separate assemblies that rely on the first.

E.g.

// myproject.interfaces.dll
interface IA 
{
    void Process(IB b);
}

interface IB
{
    void Process(IA a);
}

// myproject.A.dll - depends on myproject.interfaces.dll
class A : IA
{
    ....
}

Upvotes: 1

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

  • Compile B.dll with class B changed to remove dependency on A
  • Compile A.DLL with B.dll and class A depending on B
  • recompile B.DLL with complete class B

If interfaces of classes don't change you may be able to recompile just one without source of another.

Should you go this route - no.

Upvotes: 4

Related Questions