How to handle custom Properties in AutoMapper

On automapper where you create the Map you can specify additional processes for specific members of the destination type. So where your default map would be Mapper.Map<Domain.User, UsersDetailsViewModel>(); there is a fluent syntax to define the more complicated mappings: Mapper.Map<Domain.User, UsersDetailsViewModel>() .ForMember(vm=>vm.UserName, m=>m.MapFrom(u=>(u.UserName != null) ? u.UserName : “User” + u.ID.ToString())); Here the ForMember takes … Read more

How are you populating/validating your ViewModels?

I inject a service into the controller, not a repository, and then use AutoMapper to convert it into a view model. The benefit of the service layer in this case is that it could aggregate multiple simple operations from one or more repositories into a single operation exposing a domain model. Example: private readonly ICustomerService … Read more

Mapping Validation Attributes From Domain Entity to DTO

If you’re using something supporting DataAnnotations, you should be able to use a metadata class to contain your validation attributes: public class ProductMetadata { [NotEmpty, NotShorterThan10Characters, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } and add it in the MetadataTypeAttribute on both the domain entity & DTO: … Read more

vue.js – Organize big single page application with multiple views

Nested subviews can be resolved by using v-view and v-ref. html <div id=”main”> <div v-view=”currentView” v-ref=”view”></div> </div> <ul> <li><a href=”#/”>top</a></li> <li><a href=”#/nest/view1″>nest/view1</a></li> <li><a href=”#/nest/view2″>nest/view2</a></li> </ul> <script id=”top” type=”x-template”> <div>top view</div> </script> <script id=”nest” type=”x-template”> <div> <span>nest view</span> <div v-view=”subview”></div> </div> </script> javascript Vue.component(‘top’, Vue.extend({ template: “#top”, })); Vue.component(‘nest’, Vue.extend({ template: ‘#nest’, components: { view1: Vue.extend({ … Read more

How to inject a ViewModel into a composable function using Hilt (Jetpack Compose)

From version androidx.hilt:hilt-navigation-compose:1.0.0-alpha02 you can inject view model into Composable functions by: hiltViewModel<ViewModelType>() Example: @Composable fun LoginScreen(viewModel: LoginViewModel) {} LoginScreen( viewModel = hiltViewModel<LoginViewModel>() ) Android Developer Documentation compose and hilt UPDATE: import androidx.hilt.navigation.compose.hiltViewModel @Composable fun LoginScreen( viewModel: LoginViewModel = hiltViewModel() ){ val videos=vm.watchLater.observeAsState() val context= LocalContext.current }

getViewLifecycleOwner() in DialogFragment leads to crash

This happens because of how the DialogFragment is created. If you use onCreateDialog() than a slightly different lifecycle is used for this type of Fragment. The onCreateView() will not be used, thus the viewLifecycleOwner for this Fragment won’t be initialized. As a workaround for this, you can use the Fragment instance as the owner for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)