4

I am working on EWS. A class is made to query mail box and read emails.

public class MailReader
{
 private readonly ExchangeService _service;
 private readonly PropertySet _propertySet;
 private readonly IFolderSearch _folder;
 private readonly IMailAttachmentAdapter _attachment;
 private const int MaxEmail = 1000; 
 public MailReader(
 ExchangeService service,
 PropertySet propertySet,
 IFolderSearch folder,
 IMailAttachmentAdapter attachment)
 {
 _service = service;
 _folder = folder;
 _propertySet = propertySet;
 _attachment = attachment;
 }

what is the best way to inject ExchangeService , PropertySet classes are sealed and with no interface. Planning to use AutoFac for dependency management.

any pointers will be helpful.

asked Feb 15, 2018 at 14:48
3
  • 1
    If you don't need to substitute these dependencies, then injecting the concrete classes like you do seem fine. Commented Feb 15, 2018 at 15:29
  • 2
    I would hit the vendor with a club, a big one. Who does distribute concrete classes with no interface in 2018? The 80s have called... Commented Feb 16, 2018 at 4:51
  • 1
    Create the interface yourself, has the added benefit of decoupling. Commented Feb 16, 2018 at 6:36

1 Answer 1

5

One of the simplest, but long-winded, ways to solve this is to use the delegation pattern:

interface IDelegatedExchangeService
{
 bool AcceptGzipEncoding { get; set; }
 string ClientRequestId { get; set; }
 ...
}
class ConcreteExchangeService : IDelegatedExchangeService
{
 private ExchangeService _exchangeService;
 public bool AcceptGzipEncoding
 {
 get => _exchangeService.AcceptGzipEncoding;
 set => _exchangeService.AcceptGzipEncoding = value;
 }
 ...
}

and to then use IDelegatedExchangeService throughout your code.

answered Feb 15, 2018 at 15:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.