Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:07:49+00:00 2026-06-18T12:07:49+00:00

I have a Lazy property in my class: private Lazy<ISmtpClient> SmtpClient { get {

  • 0

I have a Lazy property in my class:

private Lazy<ISmtpClient> SmtpClient
    {
        get
        {
            return new Lazy<ISmtpClient>(() => _objectCreator.Create<ISmtpClient>(), true);
        }
    }

Also a methode that uses this proptery:

public void SendEmail(MailMessage message)
    {
        SmtpClient.Value.ServerName = "testServer";
        SmtpClient.Value.Port = 25;

        SmtpClient.Value.Send(message);
    }

But in my SmtpClient, in Send(string message) methode are all the propteries that i initialized in the above SendEmail(MailMessage message) methode, null.

How can i fix this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:07:50+00:00Added an answer on June 18, 2026 at 12:07 pm

    You are using Lazy<T> wrong.

    When using Lazy<T> you expose a property of the actual type and you have one Lazy<T> instance. You don’t create a new one every time the property is accessed:

    Lazy<ISmtpClient> _smtpClient =
        new Lazy<ISmtpClient>(() => _objectCreator.Create<MySmtpClient>(), true);
    
    private ISmtpClient SmtpClient
    {
        get
        {
            return _smtpClient.Value;
        }
    }
    

    Now, the first time the SmtpClient property is accessed, the object creator creates a new instance of MySmtpClient. This is returned. On subsequent calls, the same instance is returned.

    The usage would be like this:

    public void SendEmail(MailMessage message)
    {
        SmtpClient.ServerName = "testServer";
        SmtpClient.Port = 25;
    
        SmtpClient.Send(message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have a class (Foo) which lazy loads a property named (Bar). What is
Have you ever used lazy C++? I am trying to create .CPP files out
I have two simple POCO classes; I'm trying to get the MyY property below
Assume we have following JPA Entities: class Parent { @Id private Long id; }
I have a column class which uses view model base to implement INotifyPropertyChanged (lazy
When the property have some collection type like public IList<MyItemClass> MyList{ get; } IMHO,
I have a cart model class that has a List property like so: public
Simple question I have a class say person who has as a property a
I have the following classes: public abstract class BaseClass { private readonly double cachedValue;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.