Component Basics

From Virtual World Web Wiki
Jump to: navigation, search

As explained in the Component Programming Guide, Virtual World Web server component are .NET assemblies (.dll files) that are loaded at run-time by the VWW server software.

Project References

ASP.NET MVC 5 - Components can contain ASP.NET controllers, views, and other classes that help to extend the Admin Web, and also the Web View. For this reason component project reference the ASP.NET MVC 5 libraries, and the project type is set to {349c5851-65df-11da-9384-00065b846f21} (ASP.NET MVC 5 Project) and {fae04ec0-301f-11d3-bf4b-00c04f79efbc} (C# Class Library) via the .csproj file. This helps Visual Studio know to enable project functionality related to standard web projects. (Specifically, better Razor view support, controller to view F12 linkage in the editor, right-click context options for creating controllers and views, etc).

Entity Framework - Components can have their own databases, or add schema to the main database. Entity Framework is our chosen Object Relational Mapper (ORM), and greatly reduces the complexity of working with SQL databases. A stubbed out data model is included in the project and ready for your extension. Please note it is Highly Discouraged to talk directly to layer one database tables: that's what the Layer One API is for.

Newtonsoft.JSON - Pretty much the C# JSON framework of choice for most developers. We reference it because... you'll probably use it.

Managed Extensibility Framwork (MEF) - Found in System.ComponentModel.Composition, and is the mechanism by which the server finds component functionality and binds to it. It is also used by components to find and bind to each other. (see [MEF Documentation])

VWW Server API - Interface definitions for server and components. This is the main glue that connects your component to the server.

VWW Core Libraries - Our libraries. These include various types that form the core of our Document Object Model, network protocol handlers, and various other tools. VWW.CoreLibs.Data, VWW.CoreLibs.Debugging, VWW.CoreLibs.DOM, VWW.CoreLibs.Network, VWW.CoreLibs.ScriptHost, VWW.CoreLibs.Shared, VWW.CoreLibs.Web.

Removing Optional Parts

MEF, the VWW Server API and VWW Core Libraries are not optional. You'll need them to do anything useful as a component.

If you don't plan to extend the Admin Web, you can remove the Admin and Admin Logic folders from your project. If you don't plan to expand the Web View you can remove the WebView and WebViewLogic folders from your project. If you don't plan to use either, you can completely remove the ASP.NET MVC 5 NuGet package references as well as the App_Start folder.

If you don't plan to have your own database schema, you can remove the Database, and Migrations folders, and remove the Entity Framework NuGet package reference as well.

Newtonsoft.JSON is an optional NuGet reference and can be safely removed as well.

Component Template Project Contents

Properties - A standard project folder

AssemblyInfo.cs - Describes your component with several assembly level metadata attributes.

AdminLogic - Code that extends the Admin Web service.

AdminLogic.cs - Defines a singleton that exists when running on the Admin Web and binds service lifetime events.

Areas - Your extensions to the Admin Web. Contains your component's ASP.NET MVC Area, including it's controllers, models, views, etc.

Callbacks - Contains user interface handlers.

Controllers - Contains the ASP.NET MVC controller that extends base admin Admin Web functionality (like the side navbar).

AdminExtensionsController.cs

Database - Your Entity Framework data model

DataModel.cs - Your Entity Framework data model definition
Entities - Classes representing each data model entity type (your tables / data objects)

HostLogic - Code that extends the Instance Host service.

HostLogic.cs - Defines a singleton that exists when running on the Instance Host and binds service lifetime events.

Migrations - Generated data model migrations, allowing your database to be automatically upgraded as you improve it.

Models - Contains the base ASP.NET MVC controllers that your Admin Web and Web View controllers should inherit.

AdminController.cs - The base class for your Admin Web controllers
WebViewController.cs - The base class for your Web View controllers

ProviderLogic - Code that extends the Service Provider service.

ProviderLogic.cs - Defines a singleton that exists when running on the Service Provider and binds service lifetime events.

WebViewLogic - Code that extends the Web View service.

WebViewLogic.cs - Defines a singleton that exists when running on the Web View and binds service lifetime events.

Views - The ASP.NET MVC Views for AdminExtensionsController.cs

PackageKnown.cs - Constant definitions. The component equivalent of the Layer One WellKnown type.

packages.config - NuGet package references

web.config - Glue to help the editor work better with the project as though it were a website project.