SlideShare a Scribd company logo
1 of 9
Proxy Pattern/C# Core 2
System.Reflection.DispatchProxy
What is the Proxy Pattern?
• The intent of the proxy-pattern is to provide a placeholder for another object to
control access to it. It introduces an additional level of indirection. There are
several reasons why you would want to do this,
• defer the full cost of its creation and initialization until we actually need to
use it.
• A remote proxy is responsible for encoding a request and its arguments and for
sending (and retrieving) the request (and the response) to the real object.
• A virtual proxy may cache additional information about the real subject so that
it can postpone the access to it.
• A protection proxy checks whether the caller has sufficient access permissions
for perform a request.
• In many cases, real world proxies are a combination of some of these basic
proxies
What is System.Reflection.DispatchProxy?
• Provides a class to dynamically create proxy types that implement
a specified interface and derive from a specified DispatchProxy
type. Method invocations on the generated proxyinstance are
dispatched to that DispatchProxy base type.
How to use Proxy Pattern in C# Core 2
• You will need the package System.Reflection.DispatchProxy
ServiceControllerA
Client Factory
ServiceControllerB
ServiceA
Configuration
Service A
My Service : ServiceA
public class ServiceA : IServiceA
{
public string GetName()
{
return "Michel Bruchet";
}
}
My two controllers : Controller A and B
public class ControllerA : IServiceA
{
public string GetName()
{
return new ServiceA().GetName();
}
}
My two Classes Proxy
public class ClassProxyA : System.Reflection.DispatchProxy
{
protected override object Invoke(MethodInfo targetMethod, object[] args)
{
return new ControllerA().GetName();
}
}
My Factory
public IServiceA GetService()
{
if (_type == "A")
return DispatchProxy.Create<IServiceA, ClassProxyA>();
else
return DispatchProxy.Create<IServiceA, ClassProxyB>();
}
}
My Client
static void Main(string[] args)
{
var factory = new MyClassFactory("A");
var name = factory.GetName();
Console.Write($"hello {name}");
}

More Related Content

Similar to Proxy pattern

DS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfDS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfVarshaBaini
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik TambekarPratik Tambekar
 
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...Brian Campbell
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and modelsMayank Jain
 
Developing applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDKDeveloping applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDKHorea Porutiu
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareZongXian Shen
 
Distributed Objects and Remote Invocation
Distributed Objects and Remote InvocationDistributed Objects and Remote Invocation
Distributed Objects and Remote InvocationMedicaps University
 
remote method invocation
remote method invocationremote method invocation
remote method invocationRavi Theja
 
20CS2021-Distributed Computing module 2
20CS2021-Distributed Computing module 220CS2021-Distributed Computing module 2
20CS2021-Distributed Computing module 2Kathirvel Ayyaswamy
 

Similar to Proxy pattern (20)

DS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfDS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdf
 
Distributed objects
Distributed objectsDistributed objects
Distributed objects
 
About HTTP and REST
About HTTP and RESTAbout HTTP and REST
About HTTP and REST
 
Lets Make our Web Applications Secure
Lets Make our Web Applications SecureLets Make our Web Applications Secure
Lets Make our Web Applications Secure
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
 
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
 
009693652.pdf
009693652.pdf009693652.pdf
009693652.pdf
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and models
 
Developing applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDKDeveloping applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDK
 
Proxy Server
Proxy ServerProxy Server
Proxy Server
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malware
 
Distributed Objects and Remote Invocation
Distributed Objects and Remote InvocationDistributed Objects and Remote Invocation
Distributed Objects and Remote Invocation
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
20CS2021 Distributed Computing
20CS2021 Distributed Computing 20CS2021 Distributed Computing
20CS2021 Distributed Computing
 
005281271.pdf
005281271.pdf005281271.pdf
005281271.pdf
 
20CS2021-Distributed Computing module 2
20CS2021-Distributed Computing module 220CS2021-Distributed Computing module 2
20CS2021-Distributed Computing module 2
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Rmi
RmiRmi
Rmi
 
18CS3040 Distributed System
18CS3040 Distributed System	18CS3040 Distributed System
18CS3040 Distributed System
 

More from Michel Bruchet

Rechercherunproduit pitch-en
Rechercherunproduit pitch-enRechercherunproduit pitch-en
Rechercherunproduit pitch-enMichel Bruchet
 
Rechercherunproduit pitch
Rechercherunproduit pitchRechercherunproduit pitch
Rechercherunproduit pitchMichel Bruchet
 
Microservices architecture v2
Microservices architecture v2Microservices architecture v2
Microservices architecture v2Michel Bruchet
 
Configure an environnement for ASP.NET Core 2
Configure an environnement for ASP.NET Core 2Configure an environnement for ASP.NET Core 2
Configure an environnement for ASP.NET Core 2Michel Bruchet
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureMichel Bruchet
 
Architecture multi tiers et système de notification
Architecture multi tiers et système de notificationArchitecture multi tiers et système de notification
Architecture multi tiers et système de notificationMichel Bruchet
 
Video3 mise enplacedaikibo
Video3 mise enplacedaikiboVideo3 mise enplacedaikibo
Video3 mise enplacedaikiboMichel Bruchet
 
Video2 agilite etscalabiliteentreprise
Video2 agilite etscalabiliteentrepriseVideo2 agilite etscalabiliteentreprise
Video2 agilite etscalabiliteentrepriseMichel Bruchet
 
Aspnetcore introduction
Aspnetcore introductionAspnetcore introduction
Aspnetcore introductionMichel Bruchet
 
Startpoint - Sprint 2 - Objectifs
Startpoint - Sprint 2 - ObjectifsStartpoint - Sprint 2 - Objectifs
Startpoint - Sprint 2 - ObjectifsMichel Bruchet
 
Devops - VSTS - Source
Devops - VSTS - SourceDevops - VSTS - Source
Devops - VSTS - SourceMichel Bruchet
 

More from Michel Bruchet (20)

Meetup daikibo 1
Meetup daikibo 1Meetup daikibo 1
Meetup daikibo 1
 
Rechercherunproduit pitch-en
Rechercherunproduit pitch-enRechercherunproduit pitch-en
Rechercherunproduit pitch-en
 
Rechercherunproduit pitch
Rechercherunproduit pitchRechercherunproduit pitch
Rechercherunproduit pitch
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Microservices architecture v2
Microservices architecture v2Microservices architecture v2
Microservices architecture v2
 
Configure an environnement for ASP.NET Core 2
Configure an environnement for ASP.NET Core 2Configure an environnement for ASP.NET Core 2
Configure an environnement for ASP.NET Core 2
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
About netcore2
About netcore2About netcore2
About netcore2
 
ECommerce Logging
ECommerce LoggingECommerce Logging
ECommerce Logging
 
Architecture multi tiers et système de notification
Architecture multi tiers et système de notificationArchitecture multi tiers et système de notification
Architecture multi tiers et système de notification
 
Revue sprint2
Revue sprint2Revue sprint2
Revue sprint2
 
Revue sprint 1
Revue sprint 1Revue sprint 1
Revue sprint 1
 
Video3 mise enplacedaikibo
Video3 mise enplacedaikiboVideo3 mise enplacedaikibo
Video3 mise enplacedaikibo
 
Video2 agilite etscalabiliteentreprise
Video2 agilite etscalabiliteentrepriseVideo2 agilite etscalabiliteentreprise
Video2 agilite etscalabiliteentreprise
 
Ingenius Web Services
Ingenius Web ServicesIngenius Web Services
Ingenius Web Services
 
Aspnetcore introduction
Aspnetcore introductionAspnetcore introduction
Aspnetcore introduction
 
Startpoint - Sprint 2 - Objectifs
Startpoint - Sprint 2 - ObjectifsStartpoint - Sprint 2 - Objectifs
Startpoint - Sprint 2 - Objectifs
 
StartPoint - Sprint 1
StartPoint - Sprint 1StartPoint - Sprint 1
StartPoint - Sprint 1
 
Devops - VSTS - Source
Devops - VSTS - SourceDevops - VSTS - Source
Devops - VSTS - Source
 
Devops - Git - VSTS
Devops - Git - VSTSDevops - Git - VSTS
Devops - Git - VSTS
 

Recently uploaded

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of indiaimessage0108
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escortsindian call girls near you
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdfkeithzhangding
 

Recently uploaded (20)

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of india
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our EscortsCall Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
Call Girls in East Of Kailash 9711199171 Delhi Enjoy Call Girls With Our Escorts
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
 

Proxy pattern

  • 1. Proxy Pattern/C# Core 2 System.Reflection.DispatchProxy
  • 2. What is the Proxy Pattern? • The intent of the proxy-pattern is to provide a placeholder for another object to control access to it. It introduces an additional level of indirection. There are several reasons why you would want to do this, • defer the full cost of its creation and initialization until we actually need to use it. • A remote proxy is responsible for encoding a request and its arguments and for sending (and retrieving) the request (and the response) to the real object. • A virtual proxy may cache additional information about the real subject so that it can postpone the access to it. • A protection proxy checks whether the caller has sufficient access permissions for perform a request. • In many cases, real world proxies are a combination of some of these basic proxies
  • 3. What is System.Reflection.DispatchProxy? • Provides a class to dynamically create proxy types that implement a specified interface and derive from a specified DispatchProxy type. Method invocations on the generated proxyinstance are dispatched to that DispatchProxy base type.
  • 4. How to use Proxy Pattern in C# Core 2 • You will need the package System.Reflection.DispatchProxy ServiceControllerA Client Factory ServiceControllerB ServiceA Configuration Service A
  • 5. My Service : ServiceA public class ServiceA : IServiceA { public string GetName() { return "Michel Bruchet"; } }
  • 6. My two controllers : Controller A and B public class ControllerA : IServiceA { public string GetName() { return new ServiceA().GetName(); } }
  • 7. My two Classes Proxy public class ClassProxyA : System.Reflection.DispatchProxy { protected override object Invoke(MethodInfo targetMethod, object[] args) { return new ControllerA().GetName(); } }
  • 8. My Factory public IServiceA GetService() { if (_type == "A") return DispatchProxy.Create<IServiceA, ClassProxyA>(); else return DispatchProxy.Create<IServiceA, ClassProxyB>(); } }
  • 9. My Client static void Main(string[] args) { var factory = new MyClassFactory("A"); var name = factory.GetName(); Console.Write($"hello {name}"); }