Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 816577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:51:18+00:00 2026-05-15T01:51:18+00:00

I am working on a program that will communicate with various pieces of hardware.

  • 0

I am working on a program that will communicate with various pieces of hardware. Because of the varied nature of the items it communicates and controls, I need to have a different “driver” for each different piece of hardware. This made me think that MEF would be a great way to make those drivers as plugins that can be added even after the product has been released.

I’ve looked at a lot of examples of how to use MEF, but the question that I haven’t been able to find an answer to is how to populate a MEF plugin with external data (eg. from a database). All the examples I can find have the “data” hard-coded into the assembly, like the following example:

[Export( typeof( IRule ) )]  
public class RuleInstance : IRule  
{
    public void DoIt() {}  

    public string Name  
    {  
        get { return "Rule Instance 3"; }  
    }

    public string Version  
    {  
        get { return "1.1.0.0"; }  
    }  

    public string Description  
    {  
        get { return "Some Rule Instance"; }  
    }  
}

What if I want Name, Version and Description to come from a database? How would I tell MEF where to get that information?

I may be missing something very obvious, but I don’t know what it is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:51:18+00:00Added an answer on May 15, 2026 at 1:51 am

    You would have to either pass the information to the plugin after it loaded via properties:

    [Export( typeof( IRule ) )]  
    public class RuleInstance : IRule  
    {
        puliic void DoIt() 
        { }
    
        public string Name { get; set; }
    }
    
    public class Program
    {
        [Import(typeof( IRule ))]
        public IRule instance { get; set; }
    
        public void Run()
        {
            // Load the assemblies here
    
            instance.Name = "Rule Instance 3";
        }             
    }
    

    Or the plugin could request the variables though a host interface. You can either pass the IHost instance through a property or though a constructor parameter, but constructor parameters are not simple with MEF. Here is through a property:

     [Export( typeof( IRule ) )]  
    public class RuleInstance : IRule  
    {
        puliic void DoIt() 
        { }
    
        public void Initialise()
        {
            // Load our name from the host, this cannot be done in the constructor
            string name = Host.GetName(/* some parameters? */)
        }
    
    
        public IHost Host { get; set; }
        public string Name { get; set; }
    }
    
    public interface IHost
    {
        string GetName(/* some parameters? */);
    }
    
    public class Program : IHost
    {
        [Import(typeof( IRule ))]
        public IRule instance { get; set; }
    
        public void Run()
        {
            // Load the assemblies here       
    
            // Make sure the plugins know where the host is...
            instance.Host = this;
        }             
    }
    

    You could also “Export” the database interface and “Import” it into any plugins that need database access…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that will tell what level a programmer is at
I am working on a background program that will be running for a long
I'm working a program that will have a bunch of threads processing data. Each
I'm working on a C++ program that will automatically backup my work to my
I'm working on a program that will have several users connected to each other
Recently I have started working on a program that will monitor the packets of
I'm working on a python program that will automatically combine sets of files based
I'm working on a small Ruby program that will connect to a remote MySQL
I am working on a program that needs to create a multiple temporary folders
I'm working on a program that processes many requests, none of them reaching more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.