Custom Data Source

mohsine tahri asked on December 14, 2015 23:41

Hi, im trying to develop a custom web part which will use a custom data source.

I have multiple websites, which are using the same cms application and the same VS2015 solution, they also use the same IIS website.

Each website has data which depende on it, its a jobboard, for example we have a web site called itjobs, which will list all hob offers related to the IT domain, jobwings is another web site which will list job offers in the financial domain.

My question is, will the DataSource in my custom data source, which was developed according to Kentico 7 Developer's guide work in my case, knowing that i have multiple websites in the same app.

Im asking this, cause i checked the implementation of CMSBaseDataSource.GetDataSource() and they use caching, but what will happen if multiple websites access the same cms app?

Recent Answers


Brenden Kehren answered on December 14, 2015 23:46

Webparts are or should be developed to be website agnostic. If they need to gather data for a specific site then it should have a property in the webpart which denotes this (either the current website or allow them to select a website).

0 votesVote for this answer Mark as a Correct answer

mohsine tahri answered on December 15, 2015 16:15 (last edited on December 15, 2015 16:18)

Well thats how we implemented it, i mean they all use the same webpart as a datasource, its not like we created one for each website.

We noticed that when we get the datasource, it doesnt always call "GetDataSourceFromDB" in our custom datasource control, see the code below:

public override object DataSource { get { return mDataSource ?? (mDataSource = GetDataSource()); } set { mDataSource = (DataSet)value; } }

This is the implementation for the property "DataSource", the method "GetDataSource()" will call another method "GetDataSourceFromDB()", which contain our BL, basically it will get data from DB.

Now the problem is, while trying to simulate a concurrency issue and debugging it, we noticed that in the property "DataSource", we only call the method "GetDataSource()" once, it isnt called the other time.

Actually, it happens when we clear our runtime cache, when we try to access to two websites at the same time, we noticed we get the same Data on both websites, which shouldnt be the case, each website has its own data.

When that happens, we debbuged it and found that in the datasource concerned, in the property "DataSource", we call the method "GetDataSource()" only once.

So when calling two websites at the same time, the first website will access the "DataSource" property, try reading it, it verify if its null, which will be the case, cause we just cleared the runtime cache, so it will call the method "GetDataSource()" and get the data related to the current site, then come the second website call, but in this case, we noticed that it verify if "mDataSource" is null, and it isnt, it contains the data from the first call, so the second website doesnt call the method "GetDataSource()", and we end up with the same data as the first website.

My question is, is this behavior normal, should we directly call "GetDataSourceFromDB()" int the "DataSource" reader property instead of calling the method "GetDataSource()" which do some caching.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.