SlideShare une entreprise Scribd logo
1  sur  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}");
}

Contenu connexe

Similaire à Proxy pattern

Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and models
Mayank Jain
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
Ravi Theja
 

Similaire à 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
 

Plus de Michel Bruchet

Plus de 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
 

Dernier

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Dernier (20)

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

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}"); }