Sanjay Sharma

Sanjay Sharma

  • 1.2k
  • 409
  • 25.1k

Service object initialization approach/ Static

Mar 1 2018 5:25 AM
Hi,
 
I am using IBusinessService class. I use one helper method to create instance of this class.
 
creating instancce of this class is Expensive and takes time. I want to avoid create instance when IBusinessService already initaizalize.
 
class A
{
    private readonly IBusinessService _service = API.BusinessService(); 
    
   method1();
   method2(); 
    
In above _service always created.
 
Using static suffices but observed break sometimes. application is api based so static is not recommanded I guess. 

Answers (3)