Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have declared one web page. there I have defined all the methods. I have separated the classes now to do testing easy. I have declared one more repository class to do crud operations. Instead of defining one all the methods of web page class one more time in the
repository class. Is that possible? it is working fine for me. But , I have a doubt here? Can you please somebody help me on this?

What I have tried:

Webpage class:
public partial class MSNBulkImport : System.Web.UI.Page
{

private IFactoryForMSN moqobj = null;

        public MSNBulkImport()
        {

        }

        public MSNBulkImport(IFactoryForMSN moqobj)
        {
            this.moqobj = moqobj;
        }

//Save the data in database.
        public bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP mSNBulkImportPortfolioTVP, string updatedBy)
        {
            MSNRepository mSNRepository = new MSNRepository();
            return mSNRepository.InsertBulkImportPortfoliosToDatabase(mSNBulkImportPortfolioTVP, updatedBy);
        }
}

Interface:

<pre>public interface IFactoryForMSN
    {
        
        bool InsertBulkImportPortfoliosToDatabase(MSNBulkImportPortfolioTVP mSNBulkImportPortfolioTVP, string updatedBy);
    }

Repository Class:
Here i am inheriting the webpage. Is that correct? 

public class MSNRepository : MSNBulkImport,IFactoryForMSN 
    {
}
Posted
Updated 5-Oct-18 6:36am

1 solution

Yes, but the class you inherit from has to be ultimately derived from System.Web.UI.Page.

EDIT==================================

I thk I see what you want. You don't need an interface. All you have to do is make all the methods in your base class virtual so you can override them in derived classes. See the bold/italic/underlined text.

public partial class MSNBulkImport : System.Web.UI.Page
{
    private IFactoryForMSN moqobj = null;

    public MSNBulkImport()
    {
    }

    public MSNBulkImport(IFactoryForMSN moqobj)
    {
        this.moqobj = moqobj;
    }

    //Save the data in database.
    public virtual bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP tvp, string updatedBy)
    {
        MSNRepository mSNRepository = new MSNRepository();
        return mSNRepository.InsertBulkImportPortfoliosToDatabase(tvp, updatedBy);
    }
}

//Repository Class:
public class MSNRepository : MSNBulkImport
{
    public override bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP tvp, string updatedBy)
}
 
Share this answer
 
v2
Comments
Sree(Member 12916318) 5-Oct-18 13:08pm    
Oh OK.Thank you for the suggestion. Will it affect any performance issues of the first page(MSNBulkImport)? Is that correct way of doing?
#realJSOP 5-Oct-18 13:23pm    
It should be no different than inheriting directly from the class I indicated above.
Sree(Member 12916318) 5-Oct-18 14:56pm    
Thanks for that. That I understood. My problem is that is have some methods in the msnbulkimport web page which is inheriting from the page class. That I need to use in the MSN repository class to do the crud operations by using the inheritance as I said.again I need this method in the msnbulkimport class. Can you please clarify me.
#realJSOP 5-Oct-18 15:11pm    
I don't have any idea what you want clarified. You're just talking about inheritance here. As long as the methods are public or protected, and the class that inherits your class (apprently, msnbulkimport) can use those methods. That's not the same as "Must use".
Sree(Member 12916318) 6-Oct-18 0:34am    
I am talking about the inheritance only. Instead of to recreate the methods in msn repository what I have declared in the page class(msnbulkimport), I am inheriting the msnbulkimport. Can not we able to inherit the page class(aspx page in clear) in another class? That's want to clarify. Got it. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900