-
-
Save developerdizzle/c96b1402b3ebe74de06a to your computer and use it in GitHub Desktop.
Lazy-loading virtual proxy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMyService | |
{ | |
int GetData(); | |
string GetMoreData(); | |
} | |
public class MyService : IMyService | |
{ | |
private int _data; | |
private string _moreData; | |
public MyService() | |
{ | |
_data = 123; | |
_moreData = "Some more data"; | |
} | |
public int GetData() | |
{ | |
return _data; | |
} | |
public string GetMoreData() | |
{ | |
return _moreData; | |
} | |
} | |
public class MyServiceProxy : IMyService | |
{ | |
private IMyService _service; | |
private void InitializeServiceIfNecessary() | |
{ | |
if (_service == null) | |
{ | |
_service = new MyService(); | |
} | |
} | |
public int GetData() | |
{ | |
this.InitializeServiceIfNecessary(); | |
return _service.GetData(); | |
} | |
public string GetMoreData() | |
{ | |
this.InitializeServiceIfNecessary(); | |
return _service.GetMoreData(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment