Skip to content

Instantly share code, notes, and snippets.

View sshibani's full-sized avatar

Siawash Shibani sshibani

View GitHub Profile
public class PublicationResolver : IPublicationResolver
{
private readonly DynamicMappingsRetriever _mappingsRetriever;
public PublicationResolver()
{
_mappingsRetriever = new DynamicMappingsRetriever();
}
public int ResolvePublicationId()
namespace Tridion.ContentDelivery.DynamicContent
{
public interface IPublicationMapping
{
string Domain { get; }
string Path { get; }
int PathScanDepth { get; }
string Port { get; }
string Protocol { get; }
int PublicationId { get; }
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Tridion.ContentDelivery.DynamicContent;
namespace SDlWeb8.Examples
@sshibani
sshibani / View model using extended attribute
Created October 13, 2016 12:14
View model using extended attribute
[ContentModel("product", true)]
public class Product : ViewModelBase
{
[TextField]
public string Title { get; set; }
[ProductPrice(FieldName = "productId")]
public double Price { get; set; }
}
public class ProductPriceFieldAttribute : FieldAttributeBase
{
public override IEnumerable GetFieldValues(IField field, IModelProperty property, ITemplate template, IViewModelFactory factory)
{
IEnumerable fieldValue = null;
var productId = field.Values.FirstOrDefault();
var productService = new ProductService();
var price = productService.GetProduct(productId).Price;
@sshibani
sshibani / NLog Autofac
Created May 26, 2016 11:31
NLog Autofac
public class NLogModule : Module
{
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
registration.Preparing += OnComponentPreparing;
}
private static void OnComponentPreparing(object sender, PreparingEventArgs e)
{
var t = e.Component.Activator.LimitType;
public class PageController : TridionControllerBase
{
public PageController(IPageFactory pageFactor,
IComponentPresentationFactory componentPresentationFactory,
ILogger logger,
IDD4TConfiguration configuration) :
base(pageFactor, componentPresentationFactory, logger, configuration)
{
public override ActionResult Page(string url)
public class MvcApplication : System.Web.HttpApplication
{
ILifetimeScope BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.UseDD4T();
return builder.Build();
}
protected void Application_Start()
@sshibani
sshibani / gist:cd32b9ffe4a147c68a01
Created December 29, 2015 12:11
mvc route for dd4t
routes.MapRoute(
name: "TridionPage",
url: "{*PageUrl}",
defaults: new { controller = "Page", action = "Page" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
@sshibani
sshibani / global.asax
Last active October 30, 2015 13:28
Globals.asax snippet
ILifetimeScope BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterType<HttpClientAuthentication>()
.As<DD4T.Providers.Rest.IHttpMessageHandlerFactory>();
builder.UseDD4T();
}