user6734162
user6734162

Reputation: 11

Use of same EXE application as DLL to some other Application

I have a requirement in .Net that an application that is running as .EXE (executable say A.EXE ) be used in some other application that is again another .EXE (executable say B.EXE)

Also A is such that it uses a third party API that needs to be running compulsorily for A.EXE to run.

So right now, we are making an arrangement of opening A from B as executable itself. the application opens up as exe. This is making three executable to run at same time for a small functionality. (A.EXE , B.EXE and someAPI.EXE)

Is there any possibility of better design without so many applications open at the same time. Ofcourse we cannot avoid A's dependency with thridparty API but we can modify A such that it runs as EXE and also some functionality may be used in B.EXE.

but How? please suggest.

Upvotes: 1

Views: 98

Answers (2)

Dmitry Egorov
Dmitry Egorov

Reputation: 9650

An executable .Net assembly can be used as a library by another .Net assembly as if it were a .dll. All you need is just expose the API as you would do with a library.

Say, you've got your desired functionality in the DoTheBusiness() method in the A, then you may expose it in a public API class and use it in both A and B. But don't forget to make a reference to A.exe (or A.*proj) in the B's project.

Simplified A:

namespace A
{
    public class Aapi
    {
        public static void DoTheBusiness()
        {
            Console.WriteLine("Aapi::DoTheBusiness: DONE!");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Aapi.DoTheBusiness();
        }
    }
}

Simplified B:

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            A.Aapi.DoTheBusiness();
        }
    }
}

Upvotes: 0

Fischermaen
Fischermaen

Reputation: 12458

I would put all the functionality used by both A.EXE and B.EXE in one assembly (let's name it SharedFunctionality.dll). So both exe can us that assembly and A.EXE can use the 3rd-party API in addition.

Upvotes: 1

Related Questions