Composable Part exports
[Export]
public class SomeComposablePart {
...
}
public class SomeComposablePart {
...
}
Property exports
代码
public class Configuration
{
[Export("Timeout")]
public int Timeout
{
get { return int.Parse(ConfigurationManager.AppSettings["Timeout"]); }
}
}
[Export]
public class UsesTimeout
{
[Import("Timeout")]
public int Timeout { get; set; }
}
{
[Export("Timeout")]
public int Timeout
{
get { return int.Parse(ConfigurationManager.AppSettings["Timeout"]); }
}
}
[Export]
public class UsesTimeout
{
[Import("Timeout")]
public int Timeout { get; set; }
}
Method exports
代码
public class MessageSender
{
[Export(typeof(Action<string>))]
public void Send(string message)
{
Console.WriteLine(message);
}
}
[Export]
public class Processor
{
[Import(typeof(Action<string>))]
public Action<string> MessageSender { get; set; }
public void Send()
{
MessageSender("Processed");
}
}
{
[Export(typeof(Action<string>))]
public void Send(string message)
{
Console.WriteLine(message);
}
}
[Export]
public class Processor
{
[Import(typeof(Action<string>))]
public Action<string> MessageSender { get; set; }
public void Send()
{
MessageSender("Processed");
}
}
代码
public class MessageSender
{
[Export("MessageSender")]
public void Send(string message)
{
Console.WriteLine(message);
}
}
[Export]
public class Processor
{
[Import("MessageSender")]
public Action<string> MessageSender { get; set; }
public void Send()
{
MessageSender("Processed");
}
}
{
[Export("MessageSender")]
public void Send(string message)
{
Console.WriteLine(message);
}
}
[Export]
public class Processor
{
[Import("MessageSender")]
public Action<string> MessageSender { get; set; }
public void Send()
{
MessageSender("Processed");
}
}
Inherited Exports
[InheritedExport]
public interface ILogger {
void Log(string message);
}
public class Logger : ILogger {
public void Log(string message);
}
public interface ILogger {
void Log(string message);
}
public class Logger : ILogger {
public void Log(string message);
}