471,337 Members | 888 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 1603
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Christoph Haas | last post: by
5 posts views Thread by Michael McCarthy | last post: by
reply views Thread by Greg Conely via .NET 247 | last post: by
5 posts views Thread by Mike D Sutton | last post: by
1 post views Thread by sergio montero | last post: by
reply views Thread by rosydwin | last post: by

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.