Posts

Showing posts from February, 2023

Sitecore Dependency Injection Part - 1

Image
Introduction: In this Article we will try to see how we can implement Dependency Injection with examples. We will continue building on the the glass mapper sample created in our Previous blog. With Inheritance and Interface, we achieve loose coupling, but dependency injection (DI) take it one step ahead. in summary DI takes away all the mapping (which Interface will create which instance) at configuration level. Implementation: 1 -  Setup IServicesConfigurator: First thing to do is create a IServicesConfigurator. At this point it is a bit tricky part. If this is for the first time you are adding " IServicesConfigurator ", You will get first error message stating reference need to be added for " Sitecore.DependencyInjection " after this, the warning Quigley line will still remain on " IServicesConfigurator ". If you hoverover it, you will see it states "needs   Microsoft.Extensions.DependencyInjection   to work but not installed". Here is the catc...

Sitecore Glass mapper ReferenceField (DropLink)

Image
   Introduction: In this post we will see how we can leverage ORM concept in Sitecore as well. We will start with simple project and introduce Glass mapper. Reference Field will be our main focus in the post.  Background: We have updated sitecore Home Page with our Layout and Controller Rendering. Given below is the pictorial view. Layout : Under Layout Section in Content Editor fig-1 Create a mvc Layout. My layout just contain a Place holder as shown below fig-2 for this post we will just be using Static place holder i.e "smain" Rendering: We will be creating a rendering and data source for the same. Under Feature folder create new rendering folder -> than create Controller Rendering. The Controller field will contain , Name Space + Controller Class and with comma separated, we mention which dll contain this class. Action contains Method to hit in the Controller. fig-3 Add the layout and rendering to Home Item as shown below. By This time I hope we all know how to add...

Sitecore MVC Editable Fields

Image
Introduction: In this post we will be focusing on how we can make fields Editable in Experience Editor. We all know that if our view is been created using  "@Html.Sitecore().Field ", the fields are editable in experience editor. but the whole point comes out here is how to make this happen?.  Explanation: Let us continue on the Same example we have been working on Let us try to directly convert the Fields we have using  "@Html.Sitecore().Field". Let us see if this is editable or not. fig-1 Let us publish this and go to Experience editor to find out if we can Edit the same (we all know it wont be editable but for confirmation let us do it and see.) fig-2 All we observe here is when we hover over the Fields both in Mumbai and Hamirpur. we get no option to edit. Let us go back to our Show.cshtml and try converting the Html field into Sitecore editable fields. fig-3 You will see that we have a error. Just to confirm that error is not directly related to the statement me...

Sitecore MVC Project creation

Image
   Introduction: In this post we will integrate an ASP.Net MVC application with Installed Sitecore Instance. This should be simple and straight forward mechanism.  Background:  I have a site that is up and running after installation as shown below. fig-1 Now we will create an ASP.Net MVC Empty Application from Visual Studio. fig-2 Search for ASP.Net MVC and then select application without core as shown below. fig-3 Given the name as you prefer for this Application but I would suggest to keep the name similar to your Sitecore Web instance.  fig-4 Now select MVC blank and click create. fig-5 Once your a re done creating the application it will look like this. fig-6 As we know from Sitecore, Global.asax file is been provided by Sitecore while installation, thus, we need not need this one. We will delete this file. Similarly Web config files we will delete them as well.  fig-7   fig-8 Now go to your Sitecore Installed Instance and check the Version of Site...