かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[C#][MEF]Managed Extensibility Framework入門 その4

[C#][MEF]Managed Extensibility Framework入門 その1
[C#][MEF]Managed Extensibility Framework入門 その2
[C#][MEF]Managed Extensibility Framework入門 その3

今回は、ExportAttributeをプロパティにつけたときの動作を見てみようと思います。
今までのExportは、一般的なDIコンテナにありがちな感じで、クラスにつけて他のクラスから使えるようにしていました。

このExport属性は、実はクラスだけではなく、プロパティにつけることもできます。こうすることで、プロパティの戻り値をImportのついているプロパティに設定することが出来ます。

using System;
using System.ComponentModel.Composition;

namespace MEFExportEdu
{
    // メッセージを提供する人
    public class MessageProvider
    {
        // Messageという名前でExport
        [Export("Message")]
        public string GreetMessage
        {
            get
            {
                return "Hello world";
            }
        }
    }

    [Export]
    public class Greeter
    {
        // MessageをImport
        [Import("Message")]
        public string Message { get; set; }

        public void Greet()
        {
            // 結果としてHello worldが表示されます
            Console.WriteLine(Message);
        }
    }

}

そして、確認用のMainを作ります。

using System.ComponentModel.Composition.Hosting;

namespace MEFExportEdu
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalog = new AssemblyCatalog(typeof(Program).Assembly);
            var container = new CompositionContainer(catalog);

            // 実行!
            var g = container.GetExportedObject<Greeter>();
            g.Greet();
        }
    }
}

実行するとHello worldが表示されます。
image

この例では、とても無駄なような気がしますが、構成ファイルから読み込んだ文字列を、属性を指定するだけでさくっと取得できるようなことも出来そう。

投稿日時 : 2009年7月2日 0:22

Feedback

# welded ball valve 2012/10/19 1:03 http://www.jonloovalve.com/Full-welded-ball-valve-

I really like your writing style, great info, appreciate it for posting :D. "I will show you fear in a handful of dust." by T. S. Eliot.

# Nike Air Max 95 Womens 2012/12/08 0:24 http://superairmaxshoes.webs.com/

I like this post, enjoyed this one appreciate it for putting up. "No man is wise enough by himself." by Titus Maccius Plautus.

# Christian Louboutin boots 2012/12/08 3:28 http://mychristianlouboutinonline1.webs.com/

I like this post, enjoyed this one regards for posting. "To the dull mind all nature is leaden. To the illumined mind the whole world sparkles with light." by Ralph Waldo Emerson.

# トリーバーチ 2012/12/14 20:38 http://www.torybruchjp.info/category/トリーバーチ-靴

The only individuals who would search good donning these fugly things would be Ferrari pit crew while in the pits:D

# burberry uk 2012/12/15 22:47 http://www.burberryuksale.co/burberry-uk-bags-c-48

This may be a really excellent site posting, im delighted I recently came across it.

# NuXHLzGLCNKVOZt 2014/08/28 11:28 http://crorkz.com/

9qjj3c It's actually a great and useful piece of information. I'm happy that you simply shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

# buy tadalafil capsules 2021/10/03 12:08 gypopsy

https://prednisonebuyon.com/ - prednisolone para que sirve

# ロレックス オイスターパーペチュアル ゴールド 2021/12/02 3:49 isrpwgbonf@excite.co.jp

激安全国送料無料!100%正規品!
【新商品!】☆安心の全品国内発送!
【超人気新品】即日発送,品質100%保証!
激安販売中!
激安通販!☆安心の全品国内発送!
愛する品を選択する高級アイテムコンセント
『激安人気』送料無料.
『最速最新2021年人気新作!!』
2年保証、返品可能、全国送料無料!
顧客サービスと速い配送でお客様に手入れ。
高品質とリーズナブルで販売
オンラインストアオファー激安輸出
超安値登場!品質保証、最安値に挑戦!
オンラインストアは、ご来店ありがとうございます.
超人気【楽天市場】

# online apotheke preisvergleich 2023/09/26 12:17 Williamreomo

https://onlineapotheke.tech/# online apotheke gГ?nstig
online apotheke gГ?nstig

# п»їonline apotheke 2023/09/26 14:16 Williamreomo

https://onlineapotheke.tech/# internet apotheke
online apotheke deutschland

# versandapotheke deutschland 2023/09/26 23:02 Williamreomo

https://onlineapotheke.tech/# versandapotheke
online apotheke deutschland

# gГјnstige online apotheke 2023/09/26 23:57 Williamreomo

https://onlineapotheke.tech/# gГ?nstige online apotheke
online apotheke preisvergleich

# п»їonline apotheke 2023/09/27 1:54 Williamreomo

http://onlineapotheke.tech/# online apotheke deutschland
gГ?nstige online apotheke

# online apotheke gГјnstig 2023/09/27 12:27 Williamreomo

http://onlineapotheke.tech/# online apotheke gГ?nstig
п»?online apotheke

# acquistare farmaci senza ricetta 2023/09/27 16:21 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacia online senza ricetta 2023/09/27 17:40 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# migliori farmacie online 2023 2023/09/27 19:31 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# farmacia online piГ№ conveniente 2023/09/27 21:26 Rickeyrof

acheter sildenafil 100mg sans ordonnance

# pills for erection https://edpillsotc.store/# - best ed pills at gnc 2023/10/08 5:05 EdPills

pills for erection https://edpillsotc.store/# - best ed pills at gnc

# buying prescription medications online 2023/10/16 3:58 Kiethamert

http://gabapentin.world/# gabapentin 300mg

# pharm canada 2023/10/16 15:50 Dannyhealm

From greeting to checkout, always a pleasant experience. https://mexicanpharmonline.com/# mexico drug stores pharmacies

# best mexican pharmacies 2023/10/16 21:13 Dannyhealm

They simplify global healthcare. http://mexicanpharmonline.shop/# reputable mexican pharmacies online

# world pharm com 2023/10/17 2:09 Dannyhealm

Love their range of over-the-counter products. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# cheap prescription medication online 2023/10/17 7:35 Dannyhealm

A trusted partner in my healthcare journey. https://mexicanpharmonline.shop/# mexican mail order pharmacies

# canadian mail order medications 2023/10/17 14:25 Dannyhealm

They maintain a high standard of hygiene and cleanliness. http://mexicanpharmonline.com/# mexican border pharmacies shipping to usa

# mexican drug stores online 2023/10/18 4:32 Dannyhealm

Read now. https://mexicanpharmonline.com/# reputable mexican pharmacies online

# rx from canada 2023/10/18 10:56 Dannyhealm

They bridge the gap between countries with their service. http://mexicanpharmonline.com/# pharmacies in mexico that ship to usa

# prescription meds from canada 2023/10/18 13:17 Dannyhealm

World-class service at every touchpoint. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# canadian rx 2023/10/19 0:18 Dannyhealm

Their online portal is user-friendly and intuitive. https://mexicanpharmonline.shop/# mexico drug stores pharmacies

# average cost of generic valtrex https://valtrex.auction/ valtrex over the counter australia 2023/10/25 1:59 Valtrex

average cost of generic valtrex https://valtrex.auction/ valtrex over the counter australia

# mexican pharmaceuticals online 2023/11/19 14:58 DavidFap

http://edpills.icu/# best non prescription ed pills

# purchase doxycycline online https://doxycycline.forum/ generic doxycycline 2023/11/25 16:37 Doxycycline

purchase doxycycline online https://doxycycline.forum/ generic doxycycline

# legitimate canadian mail order pharmacies 2023/11/30 23:53 MichaelBum

https://claritin.icu/# ventolin 100mcg online

# paxlovid generic 2023/12/01 8:11 Mathewhip

paxlovid cost without insurance http://paxlovid.club/# Paxlovid buy online

# farmacia envíos internacionales 2023/12/07 21:33 RonnieCag

https://farmacia.best/# farmacia barata

# farmacias baratas online envío gratis 2023/12/08 3:49 RonnieCag

http://farmacia.best/# farmacia online madrid

# farmacia online 24 horas 2023/12/08 6:51 RonnieCag

https://tadalafilo.pro/# farmacia online

# farmacia online envío gratis 2023/12/08 15:15 RonnieCag

http://farmacia.best/# farmacia online madrid

# farmacias online seguras en españa 2023/12/10 11:59 RonnieCag

http://farmacia.best/# farmacia online 24 horas

# farmacia online envío gratis 2023/12/10 15:02 RonnieCag

http://farmacia.best/# farmacia online

# farmacia online envío gratis 2023/12/11 2:02 RonnieCag

https://sildenafilo.store/# sildenafilo cinfa sin receta

# farmacia 24h 2023/12/11 11:24 RonnieCag

https://sildenafilo.store/# sildenafilo 100mg sin receta

# farmacia envíos internacionales 2023/12/11 17:13 RonnieCag

http://farmacia.best/# farmacia barata

# farmacias online baratas 2023/12/11 20:44 RonnieCag

https://farmacia.best/# farmacia online

# ï»¿farmacia online 2023/12/12 3:49 RonnieCag

http://vardenafilo.icu/# farmacias online baratas

# ï»¿farmacia online 2023/12/12 7:23 RonnieCag

http://farmacia.best/# farmacia online madrid

# farmacia online envío gratis 2023/12/13 6:22 RonnieCag

http://tadalafilo.pro/# farmacia barata

# farmacias online seguras en españa 2023/12/13 12:32 RonnieCag

https://tadalafilo.pro/# farmacia online 24 horas

# Pharmacies en ligne certifiées 2023/12/14 2:27 Larryedump

https://pharmacieenligne.guru/# Pharmacie en ligne livraison 24h

# Pharmacie en ligne livraison gratuite 2023/12/15 10:23 Larryedump

https://pharmacieenligne.guru/# pharmacie ouverte

# order generic clomid without rx 2023/12/26 23:34 RaymondGrido

http://paxlovid.win/# paxlovid buy

# can i purchase clomid 2023/12/30 1:08 RaymondGrido

http://prednisone.bid/# prednisone 20mg tablets where to buy

タイトル  
名前  
Url
コメント