473,379 Members | 1,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Plugins architecture

I need to implement plugins in my application. That is to say, DLLs that
communicate with my application data.

Does someone have a link to the best explain of how to accomplish the above
?

Thanks a lot
Luis Arvayo

Jan 5 '06 #1
6 1697
One approach is to declare an interface and use reflection. Note the
call to !
t.IsAbstract which is prevents you from trying to instantiate an
interface or
abstract class!

http://www.geocities.com/Jeff_Louie/OOP/oop13.htm

assembly= Assembly.Load(dll); // in folder plugins
//Type[] types= assembly.GetTypes();
Type[] types= assembly.GetExportedTypes(); //safer
foreach(Type t in types)
{
Console.WriteLine("Type: {0}",t);
try
{
// only load if implements IDrawable
// use fully qualified name!
//if (t.GetInterface("MyInterface.IDrawable")!= null)
if (typeof(IDrawable).IsAssignableFrom(t) // safer call
&& !t.IsAbstract) // even safer call ) // <-- !!!!
{
// dynamically load this class
object obj= Activator.CreateInstance(t);
drawableList.Add(obj); // no need to cast
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Jan 6 '06 #2
Thank you for the explain !

I have one question:

Suppose I installed my application to the

c:\MyApp\App folder

then on the folder

c:\MyApp\App\plugins

I must install all the plugins DLL for the application.

Then, on the c:\MyApp\App folder I also must install the MyInterface.dll
assembly which contains the interfase declaration.

Is the above correct ?
Thanks
Luis Arvayo

"Jeff Louie" <je********@yahoo.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP12.phx.gbl...
One approach is to declare an interface and use reflection. Note the
call to !
t.IsAbstract which is prevents you from trying to instantiate an
interface or
abstract class!

http://www.geocities.com/Jeff_Louie/OOP/oop13.htm

assembly= Assembly.Load(dll); // in folder plugins
//Type[] types= assembly.GetTypes();
Type[] types= assembly.GetExportedTypes(); //safer
foreach(Type t in types)
{
Console.WriteLine("Type: {0}",t);
try
{
// only load if implements IDrawable
// use fully qualified name!
//if (t.GetInterface("MyInterface.IDrawable")!= null)
if (typeof(IDrawable).IsAssignableFrom(t) // safer call
&& !t.IsAbstract) // even safer call ) // <-- !!!!
{
// dynamically load this class
object obj= Activator.CreateInstance(t);
drawableList.Add(obj); // no need to cast
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***

Jan 7 '06 #3
Yes.. it is.

but, please note that AppendPrivatePath is deprecated - so you shouldn't
use it.

to get the same sort of functionality you can use an app.config. here
is an example that looks in the plugins and utilities folders:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Plugins;Utilities"/>
</assemblyBinding>
</runtime>
</configuration>

Luis Arvayo wrote:
Thank you for the explain !

I have one question:

Suppose I installed my application to the

c:\MyApp\App folder

then on the folder

c:\MyApp\App\plugins

I must install all the plugins DLL for the application.

Then, on the c:\MyApp\App folder I also must install the MyInterface.dll
assembly which contains the interfase declaration.

Is the above correct ?
Thanks
Luis Arvayo

"Jeff Louie" <je********@yahoo.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP12.phx.gbl...
One approach is to declare an interface and use reflection. Note the
call to !
t.IsAbstract which is prevents you from trying to instantiate an
interface or
abstract class!

http://www.geocities.com/Jeff_Louie/OOP/oop13.htm

assembly= Assembly.Load(dll); // in folder plugins
//Type[] types= assembly.GetTypes();
Type[] types= assembly.GetExportedTypes(); //safer
foreach(Type t in types)
{
Console.WriteLine("Type: {0}",t);
try
{
// only load if implements IDrawable
// use fully qualified name!
//if (t.GetInterface("MyInterface.IDrawable")!= null)
if (typeof(IDrawable).IsAssignableFrom(t) // safer call
&& !t.IsAbstract) // even safer call ) // <-- !!!!
{
// dynamically load this class
object obj= Activator.CreateInstance(t);
drawableList.Add(obj); // no need to cast
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***


Jan 7 '06 #4
Thank you !

It worked perfectly. I don't know why, but it worked :-)

Regards
Luis Arvayo

"Benny Raymond" <be***@pocketrocks.com> escribió en el mensaje
news:ON**************@tk2msftngp13.phx.gbl...
Yes.. it is.

but, please note that AppendPrivatePath is deprecated - so you shouldn't
use it.

to get the same sort of functionality you can use an app.config. here is
an example that looks in the plugins and utilities folders:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Plugins;Utilities"/>
</assemblyBinding>
</runtime>
</configuration>

Luis Arvayo wrote:
Thank you for the explain !

I have one question:

Suppose I installed my application to the

c:\MyApp\App folder

then on the folder

c:\MyApp\App\plugins

I must install all the plugins DLL for the application.

Then, on the c:\MyApp\App folder I also must install the MyInterface.dll
assembly which contains the interfase declaration.

Is the above correct ?
Thanks
Luis Arvayo

"Jeff Louie" <je********@yahoo.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP12.phx.gbl...
One approach is to declare an interface and use reflection. Note the
call to !
t.IsAbstract which is prevents you from trying to instantiate an
interface or
abstract class!

http://www.geocities.com/Jeff_Louie/OOP/oop13.htm

assembly= Assembly.Load(dll); // in folder plugins
//Type[] types= assembly.GetTypes();
Type[] types= assembly.GetExportedTypes(); //safer
foreach(Type t in types)
{
Console.WriteLine("Type: {0}",t);
try
{
// only load if implements IDrawable
// use fully qualified name!
//if (t.GetInterface("MyInterface.IDrawable")!= null)
if (typeof(IDrawable).IsAssignableFrom(t) // safer call
&& !t.IsAbstract) // even safer call ) // <-- !!!!
{
// dynamically load this class
object obj= Activator.CreateInstance(t);
drawableList.Add(obj); // no need to cast
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***



Jan 7 '06 #5
Hi Benny... I hope you don't mind if I add your code snippet to my
article.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Jan 8 '06 #6
Try these : http://mrbelles.brinkster.net/blogs/...g/default.aspx
Also try :www.codeproject.com , look for "Razor Framework"
"Jeff Louie" <je********@yahoo.com> wrote in message
news:Oj****************@TK2MSFTNGP11.phx.gbl...
Hi Benny... I hope you don't mind if I add your code snippet to my
article.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***

Feb 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: stu_pb | last post by:
I am designing a plugin system for a window application using .NET(C# specifically). One of the requirements of the plugin system is to be able to dynamically load/unload plugins. My initial...
5
by: Christoph Haas | last post by:
Dear coders... I'm working on an application that is supposed to support "plugins". The idea is to use the plugins as packages like this: Plugins/ __init__.py Plugin1.py Plugin2.py...
5
by: Michael McCarthy | last post by:
I want to develop plugin support for a system.montitor module I am working on. A lot of the modules will do mostly interop stuff for an older system, but I want to use it myself as well to monitor...
2
by: ekz | last post by:
Hey there , I have an architectural question : I am working on CMS application build with ASP.Net and CSharp + SQL Server 2000 This application should be product that the company will continue to...
0
by: Greg Conely via .NET 247 | last post by:
I am creating a application that will be using plugins. I am doing this so that when I want to let this application work with another type of dbase system, I only have to write\install one plugin,...
5
by: Mike D Sutton | last post by:
Hi, I'm porting an old project over to C# which makes heavy use of plugins, however I'm not sure the way I've approached it is the best technique. In the old project, I had a TypeLib with the...
1
by: dandorey1 | last post by:
I'm currently in the process of writing a realtime telephony application. I've designed it with a fairly simply plugin architecture. When I first started reading about this the general suggestion...
1
by: sergio montero | last post by:
Hi, I've been searching for books or tutorials that help to undestand better the way plugins work and how they should be programmed, but I just found a few articles about the basis (interfaces,...
3
by: jmDesktop | last post by:
When you create a system that takes "plugins," does that mean that your plugins give new additional methods that were not there in the original plugin interface previously or does it only mean that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.