Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
in my project, I would like to separate the code into three different assemblies:
1.) The frontend
2.) The backend
3.) The backend's interface
Basically, the backend will implement all the interfaces that are defined by the backend's interface. Now the frontend should only know about the backend's interface, not the backend itself.
Thus both, the frontend and the backend should have a reference to the backend's interface. But they should not know each other.
Now I need a ServiceLocator that provides the frontend with implementations of the backend's interface.
Something like
DoSomethingService dss = ServiceLocator.GetService<DoSomethingService>();


But how does the ServiceLocator get the information about the implementations?
The easy way would be to put it into the backend, but then the frontend would have a dependency there, which I don't want to have.
Defining the interface and implementation via XML and using "Type.GetType(string)" in the ServiceFactory does not work either, since I need a reference to the type's implementation when trying to create the type from the string.

What other options do I have?

The application is an ASP.NET-Application with xcopy-deployment and two assemblies used: The backend and the backend's interface.

Do you have any other ideas, how I can implement this?
Posted

1 solution

Just for the record.
Simple solution: Just add ",AssemblyName" to the class-name.
I did not decide for this anyway, since it contains a central configuration-file that all service-implementors have to edit (there will be multiple assemblies for the backend and the backend's interface).
Thus I created a "Configuration"-project that is allowed to know all the service-implementing assemblies. This project does then call all the service-implementing assemblies and asks them to register their services.
Unfortunately, the configuration has to be triggered during the frontend's initialization. Thus the frontend has an indirect reference to the service-implementations. But I can live with this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900