Sdl.Web.Common/Models/ModelTypeRegistry.cs
/// <summary>
/// Registers a View Model and associated View.
/// </summary>
/// <param name="viewData">The data for the View to register or <c>null</c> if only the Model Type is to be registered.</param>
/// <param name="modelType">The model Type used by the View.</param>
Registers a View Model and associated View.
Registers a View Model and associated View .
public static void RegisterViewModel(MvcData viewData, Type modelType)
        {
            using (new Tracer(viewData, modelType))
            {
                lock (_viewToModelTypeMapping)
                {
                    if (viewData != null)
                    {
                        if (_viewToModelTypeMapping.ContainsKey(viewData))
                        {
                            Log.Warn("View '{0}' registered multiple times.", viewData);
                            return;
                        }
                        _viewToModelTypeMapping.Add(viewData, modelType);
                    }
                    lock (_modelTypeToSemanticInfoMapping)
                    {
                        if (!_modelTypeToSemanticInfoMapping.ContainsKey(modelType))
                        {
                            RegisterModelType(modelType);
                        }
                    }
                }
            }
        }
public static void RegisterViewModel ( MvcData viewData , Type modelType ) { using ( new Tracer ( viewData , modelType ) ) { lock ( _viewToModelTypeMapping ) { if ( viewData != null ) { if ( _viewToModelTypeMapping . ContainsKey ( viewData ) ) { Log . Warn ( " " , viewData ) ; return ; } _viewToModelTypeMapping . Add ( viewData , modelType ) ; } lock ( _modelTypeToSemanticInfoMapping ) { if ( ! _modelTypeToSemanticInfoMapping . ContainsKey ( modelType ) ) { RegisterModelType ( modelType ) ; } } } } }
Registers a View Model and associated View.
Registers a View Model and associated View .
// Obtain a lock on _modelTypeToSemanticInfoMapping too to prevent a race with GetSemanticInfo
viewData
MvcData
The data for the View to register or null
The data for the View to register or null
modelType
Type
The model Type used by the View.
The model Type used by the View .