473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

modular application

Hi!

I mentioned this in my other post today but at that time I though I had it
all figured out. When
I got a reply regarding my other questing I saw that I don't :)

Here's my problem:

I would like to have an application where I would write the core and the
users could write
their own addins for the application.
Even the basic features I would provide would be addins.

Here's my idea: Create a basic form, which would contain the ModuleLoader
class. That class
would read the modules.xml file and dynamiclly load all the modules.
All the modules would have to implement the interface IModule, plus
IModuleMenu if the module
would add something to the menubar.
Here comes the tricky part...
Some of the modules could provide some services. Let's say I have a module,
which communicates with
a GPS device and provides the service GPS. Another module would display a
map based on the GPS location. How would the module Map get the location
from another module?
The module could "ask" the ModuleLoader to point to the module, which
provides the service "GPS" but
I still don't have an idea as how to get the information from the module. I
could require that
if the module provides GPS service that he must have public properties:
X,Y,Z...

Another problem is module execution. Do I give each module it's own
execution thread?
Or perhaps just the ones that provide services?

Any ideas would REALLY help...
saso
Nov 15 '05 #1
7 1581
Here's what I do in a situation that is very similar to yours. My plugins
(or modules as you call them) implement interface IPlugin, and the shell
application that loads the plugins implements interface IHost. When the host
loads a plugin it gives a reference to IHost to the plugin.

One of the methods in IHost is declared like so:

IPLugin GetPlugin(Type t);

In the implementation of this method, the host goes over all loaded plugins
and returns a reference to the first plugin that implements type 't'.

Applying this approach to your case, in order to obtain a reference to the
GPS plugin and to get the location, your Map plugin would something similar
to this:

IPlugin plugin = ihost.GetPlugin (typeof(IGpsPlu gin));
IGpsPlugin gpsPlugin = (IGpsPlugin)plu gin;
Location loc = gpsPlugin.Locat ion;

This approach works for me just fine. Depending on your particular needs you
might want to tweak the logic, but anyway this is the big picture.

Regards,
Sami

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:bv******** **@planja.arnes .si...
Hi!

I mentioned this in my other post today but at that time I though I had it
all figured out. When
I got a reply regarding my other questing I saw that I don't :)

Here's my problem:

I would like to have an application where I would write the core and the
users could write
their own addins for the application.
Even the basic features I would provide would be addins.

Here's my idea: Create a basic form, which would contain the ModuleLoader
class. That class
would read the modules.xml file and dynamiclly load all the modules.
All the modules would have to implement the interface IModule, plus
IModuleMenu if the module
would add something to the menubar.
Here comes the tricky part...
Some of the modules could provide some services. Let's say I have a module, which communicates with
a GPS device and provides the service GPS. Another module would display a
map based on the GPS location. How would the module Map get the location
from another module?
The module could "ask" the ModuleLoader to point to the module, which
provides the service "GPS" but
I still don't have an idea as how to get the information from the module. I could require that
if the module provides GPS service that he must have public properties:
X,Y,Z...

Another problem is module execution. Do I give each module it's own
execution thread?
Or perhaps just the ones that provide services?

Any ideas would REALLY help...
saso

Nov 15 '05 #2
That's the approach I was thinking about...
Just a few more questions...
Do your plugins inherit from IPlugin or do the implement it? I mean do you
have this:
class MyPlugin : System.Object, IPlugin ? (or MyPlugin:
System.Windows. Forms, IPlugin or ...)

In this case, isn't the Type of MyPlugin actually MyPlugin? To get the
interface
you would then have to use MyPlugin.GetTyp e().GetInterfac e("IPlugin") and to
call
the methods of this interface you would then use MethodInfo.Invo ke(...).
And most importantly... You can't cast an object of type MyPlugin to
IPlugin, can you?

Here's what I do so far:
I load all the types in an assembly. I go through all the types and search
if those types implement
IModule. I create an instance of the object which implements the IModule
interface with:
object myObject = Activator.Creat eInstance(typeo fObject);
I then use the MethodInfo.Invo ke and PropertyInfo.Ge tValue, to start the
OnConnect method of
the plugin (OnConnect is part of IModule) and to get the list of Services
(also part of IPlugin) that the plugin provides (if any).
I then add "myObject", it's services and it's type into an array at the
host. So when some plugin would call:
Host.FindPlugin ("GPS");
The Host would find that the GpsPlugin provides the GPS service and it would
provide the
object reference and Type to the plugin which requires the question.
The main problem is:
How do I cast the GpsPlugin (which is stored at the host and received as
System.Object) to the type
of GpsPlugin (note that the host stored the Type information)?

I wouldn't want to hardcode the casting... Is this even possible?

Thanks,
saso

"Sami Vaaraniemi" <sa************ ***@jippii.fi> wrote in message
news:bv******** **@phys-news1.kolumbus. fi...
Here's what I do in a situation that is very similar to yours. My plugins
(or modules as you call them) implement interface IPlugin, and the shell
application that loads the plugins implements interface IHost. When the host loads a plugin it gives a reference to IHost to the plugin.

One of the methods in IHost is declared like so:

IPLugin GetPlugin(Type t);

In the implementation of this method, the host goes over all loaded plugins and returns a reference to the first plugin that implements type 't'.

Applying this approach to your case, in order to obtain a reference to the
GPS plugin and to get the location, your Map plugin would something similar to this:

IPlugin plugin = ihost.GetPlugin (typeof(IGpsPlu gin));
IGpsPlugin gpsPlugin = (IGpsPlugin)plu gin;
Location loc = gpsPlugin.Locat ion;

This approach works for me just fine. Depending on your particular needs you might want to tweak the logic, but anyway this is the big picture.

Regards,
Sami

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:bv******** **@planja.arnes .si...
Hi!

I mentioned this in my other post today but at that time I though I had it all figured out. When
I got a reply regarding my other questing I saw that I don't :)

Here's my problem:

I would like to have an application where I would write the core and the
users could write
their own addins for the application.
Even the basic features I would provide would be addins.

Here's my idea: Create a basic form, which would contain the ModuleLoader class. That class
would read the modules.xml file and dynamiclly load all the modules.
All the modules would have to implement the interface IModule, plus
IModuleMenu if the module
would add something to the menubar.
Here comes the tricky part...
Some of the modules could provide some services. Let's say I have a module,
which communicates with
a GPS device and provides the service GPS. Another module would display a map based on the GPS location. How would the module Map get the location
from another module?
The module could "ask" the ModuleLoader to point to the module, which
provides the service "GPS" but
I still don't have an idea as how to get the information from the

module. I
could require that
if the module provides GPS service that he must have public properties:
X,Y,Z...

Another problem is module execution. Do I give each module it's own
execution thread?
Or perhaps just the ones that provide services?

Any ideas would REALLY help...
saso


Nov 15 '05 #3

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:c0******** **@planja.arnes .si...
That's the approach I was thinking about...
Just a few more questions...
Do your plugins inherit from IPlugin or do the implement it? I mean do you
have this:
class MyPlugin : System.Object, IPlugin ? (or MyPlugin:
System.Windows. Forms, IPlugin or ...)
My plugins inherit from IPlugin - which is the same as saying they implement
IPlugin. They also happen to be Forms, so they look like this (the second
option above):

class MyPlugin : System.Windows. Forms, IPlugin

Sometimes the plugins implement a plugin-specific interface, e.g.,

interface ISpecialPlugin : IPlugin {...}

class MySpecialPlugin : System.Windows. Forms, ISpecialPlugin

All these interfaces (IPlugin, ISpecialPlugin, IHost) are defined in an
assembly which is referenced by the plugins and by the shell.

In this case, isn't the Type of MyPlugin actually MyPlugin? To get the
interface
you would then have to use MyPlugin.GetTyp e().GetInterfac e("IPlugin") and to call
the methods of this interface you would then use MethodInfo.Invo ke(...).
And most importantly... You can't cast an object of type MyPlugin to
IPlugin, can you?
Yes, the actual type of MyPlugin is MyPlugin. Due to the fact that MyPlugin
and all other plugins inherit from IPlugin, the shell can easily access the
IPlugin interface when it loads the plugin:

Assembly asm = Assembly.LoadFr om(<url>); // this string comes from
e.g., a config file
IPlugin plugin = (IPlugin)asm.Cr eateInstance("M yPlugin"); // the string
"MyPlugin" string comes from e.g., a config file

This way the shell can call the methods of IPlugin directly and there is no
need to invoke them through reflection. The shell only uses the interface,
it never uses the actual type MyPlugin.

Here's what I do so far:
I load all the types in an assembly. I go through all the types and search
if those types implement
IModule. I create an instance of the object which implements the IModule
interface with:
object myObject = Activator.Creat eInstance(typeo fObject);
I then use the MethodInfo.Invo ke and PropertyInfo.Ge tValue, to start the
OnConnect method of
the plugin (OnConnect is part of IModule) and to get the list of Services
(also part of IPlugin) that the plugin provides (if any).
This sounds fine to me except that you don't necessarily have to use
MethodInfo.Invo ke. Instead, simply cast your object to IModule:

object myObject = Activator.Creat eInstance(typeo fObject);
IModule module = (IModule)myObje ct;

In order for this to work though, you need to define the interface IModule
in a separate assembly and have your loader application reference that
assembly.
I then add "myObject", it's services and it's type into an array at the
host. So when some plugin would call:
Host.FindPlugin ("GPS");
The Host would find that the GpsPlugin provides the GPS service and it would provide the
object reference and Type to the plugin which requires the question.
The main problem is:
How do I cast the GpsPlugin (which is stored at the host and received as
System.Object) to the type
of GpsPlugin (note that the host stored the Type information)?
My earlier comments already answer this. Define the interface IGpsPlugin in
a shared assembly. Have the plugin reference that assembly. Then in the
plugin you can simply write:

IGpsPlugin gpsPlugin = (IGpsPlugin)Hos t.FindPlugin(ty peof(IGpsPlugin ));

You will not need to use reflection if you define the interfaces in a
separate assembly, and have the host and the plugins reference this
assembly. I know that some developers prefer the flexibility of reflection
over having interfaces. My personal preference (in this case) is type safety
through interfaces.
I wouldn't want to hardcode the casting... Is this even possible?

Thanks,
saso


Sure,
Sami

Nov 15 '05 #4
Thanks Sami!
You really helped me a lot!

Just one more thing :)
How do you "cast" an object if you have the Type of the object stored in
some variable t?
So you can't use:
myGpsObject = (Gps) myObject;

but instead:
myGpsObject = ??? t.GetType() ???

Again,
thanks a lot for your help

"Sami Vaaraniemi" <sa************ ***@jippii.fi> wrote in message
news:c0******** **@phys-news1.kolumbus. fi...

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:c0******** **@planja.arnes .si...
That's the approach I was thinking about...
Just a few more questions...
Do your plugins inherit from IPlugin or do the implement it? I mean do you have this:
class MyPlugin : System.Object, IPlugin ? (or MyPlugin:
System.Windows. Forms, IPlugin or ...)
My plugins inherit from IPlugin - which is the same as saying they

implement IPlugin. They also happen to be Forms, so they look like this (the second
option above):

class MyPlugin : System.Windows. Forms, IPlugin

Sometimes the plugins implement a plugin-specific interface, e.g.,

interface ISpecialPlugin : IPlugin {...}

class MySpecialPlugin : System.Windows. Forms, ISpecialPlugin

All these interfaces (IPlugin, ISpecialPlugin, IHost) are defined in an
assembly which is referenced by the plugins and by the shell.

In this case, isn't the Type of MyPlugin actually MyPlugin? To get the
interface
you would then have to use MyPlugin.GetTyp e().GetInterfac e("IPlugin") and
to
call
the methods of this interface you would then use MethodInfo.Invo ke(...).
And most importantly... You can't cast an object of type MyPlugin to
IPlugin, can you?
Yes, the actual type of MyPlugin is MyPlugin. Due to the fact that

MyPlugin and all other plugins inherit from IPlugin, the shell can easily access the IPlugin interface when it loads the plugin:

Assembly asm = Assembly.LoadFr om(<url>); // this string comes from e.g., a config file
IPlugin plugin = (IPlugin)asm.Cr eateInstance("M yPlugin"); // the string "MyPlugin" string comes from e.g., a config file

This way the shell can call the methods of IPlugin directly and there is no need to invoke them through reflection. The shell only uses the interface,
it never uses the actual type MyPlugin.

Here's what I do so far:
I load all the types in an assembly. I go through all the types and
search if those types implement
IModule. I create an instance of the object which implements the IModule
interface with:
object myObject = Activator.Creat eInstance(typeo fObject);
I then use the MethodInfo.Invo ke and PropertyInfo.Ge tValue, to start the
OnConnect method of
the plugin (OnConnect is part of IModule) and to get the list of Services (also part of IPlugin) that the plugin provides (if any).


This sounds fine to me except that you don't necessarily have to use
MethodInfo.Invo ke. Instead, simply cast your object to IModule:

object myObject = Activator.Creat eInstance(typeo fObject);
IModule module = (IModule)myObje ct;

In order for this to work though, you need to define the interface IModule
in a separate assembly and have your loader application reference that
assembly.
I then add "myObject", it's services and it's type into an array at the
host. So when some plugin would call:
Host.FindPlugin ("GPS");
The Host would find that the GpsPlugin provides the GPS service and it

would
provide the
object reference and Type to the plugin which requires the question.
The main problem is:
How do I cast the GpsPlugin (which is stored at the host and received as
System.Object) to the type
of GpsPlugin (note that the host stored the Type information)?


My earlier comments already answer this. Define the interface IGpsPlugin

in a shared assembly. Have the plugin reference that assembly. Then in the
plugin you can simply write:

IGpsPlugin gpsPlugin = (IGpsPlugin)Hos t.FindPlugin(ty peof(IGpsPlugin ));
You will not need to use reflection if you define the interfaces in a
separate assembly, and have the host and the plugins reference this
assembly. I know that some developers prefer the flexibility of reflection
over having interfaces. My personal preference (in this case) is type safety through interfaces.
I wouldn't want to hardcode the casting... Is this even possible?

Thanks,
saso


Sure,
Sami

Nov 15 '05 #5

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:c0******** **@planja.arnes .si...
Thanks Sami!
You really helped me a lot!

Just one more thing :)
How do you "cast" an object if you have the Type of the object stored in
some variable t?
So you can't use:
myGpsObject = (Gps) myObject;

but instead:
myGpsObject = ??? t.GetType() ???


You cannot get an instance out of a type simply by casting. When you cast,
you always cast a reference to an instance, like so:

object obj = new SomeClass();
// Now cast 'obj' to a reference to 'SomeClass'
SomeClass sc = (SomeClass)obj;

Btw, there are a number of articles on the net that show how to create a
pluggable architecture. I know there is one on www.codeproject.com (I can't
seem to access it now). There's another one written in VB.NET on
developerfusion .com: http://www.developerfusion.com/show/4371/ .

I also wrote a quick C# sample that shows one way of doing a pluggable
architecture. It is very similar to the articles above. My sample is
available for download at http://www.capehill.net/pluginsample.zip . I might
add some security specific stuff to this sample later if I have the time...

Sami

Nov 15 '05 #6
I did something very similar to what you have...
I just have a config file to load the modules...

What do you mean by security? Controling access to the modules? Where can I
find some
reading on this subject?

Again, thanks for all your help
saso

"Sami Vaaraniemi" <sa************ ***@jippii.fi> wrote in message
news:c0******** **@phys-news1.kolumbus. fi...

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:c0******** **@planja.arnes .si...
Thanks Sami!
You really helped me a lot!

Just one more thing :)
How do you "cast" an object if you have the Type of the object stored in
some variable t?
So you can't use:
myGpsObject = (Gps) myObject;

but instead:
myGpsObject = ??? t.GetType() ???
You cannot get an instance out of a type simply by casting. When you cast,
you always cast a reference to an instance, like so:

object obj = new SomeClass();
// Now cast 'obj' to a reference to 'SomeClass'
SomeClass sc = (SomeClass)obj;

Btw, there are a number of articles on the net that show how to create a
pluggable architecture. I know there is one on www.codeproject.com (I

can't seem to access it now). There's another one written in VB.NET on
developerfusion .com: http://www.developerfusion.com/show/4371/ .

I also wrote a quick C# sample that shows one way of doing a pluggable
architecture. It is very similar to the articles above. My sample is
available for download at http://www.capehill.net/pluginsample.zip . I might add some security specific stuff to this sample later if I have the time...
Sami

Nov 15 '05 #7

"Saso Zagoranski" <sa************ *@guest.arnes.s i> wrote in message
news:c0******** **@planja.arnes .si...
I did something very similar to what you have...
I just have a config file to load the modules...

What do you mean by security? Controling access to the modules? Where can I find some
reading on this subject?


If your application allows for extensibility via remotely loaded plugins,
you will probably want to make sure that you load only plugins that you know
you can trust. In practice this would boil down to checking that the plugin
assemblies are properly signed.

There are some articles e.g., on MSDN that touch this topic briefly, e.g.,
http://msdn.microsoft.com/netframewo...artclient.aspx .

Sami
Nov 15 '05 #8

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

Similar topics

14
3778
by: Hayden Kirk | last post by:
Hey guys I am about to write some back end software for my business. I want a system that I can create invoices, clients etc... I can do this no problem. However I want to write it in modules so its extendable in the future. Like someone else can write a module for it and it can plug stright into my system. I can't figure out a good way to do this in php. I was thinking of hooks or something, but PHP does not support this.
5
2267
by: Tim | last post by:
Dear All, I have been working with VB.NET for the last 5 months or so as a solo developer for a small business. I have already started developing the application but have hit a snag with the referencing of one project within another. I would like to develop the solution using a modular approach such that the solution will be made up of several smaller projects being referenced by a main application project. Some of these smaller
1
9941
by: Derek | last post by:
Hi All, I am developing a Windows based application that consists of several different modules. These modules are effectively separate from each other yet share information in a common database. I would like to be able deliver specific modules depending on what the needs of the client are. Some clients may only need Module A and B, while others may need the functionality in Module D. What I am trying to figure out is the best way to go...
4
2310
by: Nick Goloborodko | last post by:
Hi, I'm in the process of conceptualizing a new ASP.NET application. I'm a relative newbie in ASP.NET / .NET in general, so any comments will be greatly appreciated. Basically i need to make my application as modular as possible, something along the lines of Mambo (PHP CMS System) Drupal (another PHP CMS) or something similar to these. What I'm thinking is to provide the following structure: core of the application includes essential...
12
2215
by: Don Huan | last post by:
Hi my job is to migrate our WinForms application to ASP.NET. This app was build very modular so every peace of code can be replaced by another "modul". There are 1 VS-solution with about 60 projects (dll's) in it. Now I have to design a Web-Client modul (actually the web-interface). To maintain the modularity, I thought of making one ASP.NET-Project inside of the solution and create some projects containing Custom Web Controls. Did...
26
4857
by: I_AM_DON_AND_YOU? | last post by:
This is the scenario: I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right now I haven't used any sub procedure. I mean to say I am writing the code directly in the click event. So it's become very lengthy and therefore to figure out some problem or make any changes I have to scroll at lot. Also in addition to click...
2
1160
by: Peter Kubicsek | last post by:
Hi I need help. I'm trying to write modular APP which have only basic interfaces to work with database, and etc. All specific code will be in modules (dll's), which can be loaded/unloaded from main app. I know how to write this modules with IDTExtensibility2 interface, but don't know how to write application interface which can work with addins (modules). Can someone eplain me way how to do this? I want something like in Office App,...
0
1026
by: Leif K-Brooks | last post by:
I'm writing an application with PostgreSQL as the database which I would like to be as modular as possible. It will have various modules, each of which will have their own database schema. A module with users might define a user table, but an RPG module would want the user table to have a column for money. I don't want the users module to know about the RPG module beforehand, so it can't have the money column. Should the RPG module...
20
6824
by: Tuvas | last post by:
I have made and recently posted a libary I made to do Modular Arithmetic and Prime numbers on my website at http://www.geocities.com/brp13/Python/index.html . I am currently in a crypotology class, and am working on building a RSA public key cryptology system for a class project. I am building the librarys just to get the experience to do so. However, I would ask if any of you know of any gaping security holes that can easily be seen from...
2
3482
by: Canice | last post by:
I'm working on a web application where 90% of it is common 'product' code an the other 10% is customer specific. I want some method of separating the customer specific presentation, business and data access layers from the product code as I don't the main product code to be bloated with customer specific code. Ideally I'd like to have one solution for the product and one for each customer. However I haven't found a way to separate the...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.