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

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

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
 

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

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxeditsforyah
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 

Dernier (20)

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
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🔝
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptx
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 

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